Tabnine Logo
Multiset.count
Code IndexAdd Tabnine to your IDE (free)

How to use
count
method
in
com.google.common.collect.Multiset

Best Java code snippets using com.google.common.collect.Multiset.count (Showing top 20 results out of 1,350)

origin: google/guava

@Override
public int count(Object element) {
 int count1 = multiset1.count(element);
 return (count1 == 0) ? 0 : Math.min(count1, multiset2.count(element));
}
origin: google/guava

 @Override
 @GuardedBy("ServiceManagerState.this.monitor")
 public boolean isSatisfied() {
  return states.count(TERMINATED) + states.count(FAILED) == numberOfServices;
 }
}
origin: google/guava

@Override
public int count(@Nullable Object element) {
 int count1 = multiset1.count(element);
 return (count1 == 0) ? 0 : Math.max(0, count1 - multiset2.count(element));
}
origin: google/guava

@Override
public int count(@Nullable Object element) {
 int count = unfiltered.count(element);
 if (count > 0) {
  @SuppressWarnings("unchecked") // element is equal to an E
  E e = (E) element;
  return predicate.apply(e) ? count : 0;
 }
 return 0;
}
origin: google/guava

/** An implementation of {@link Multiset#setCount(Object, int, int)}. */
static <E> boolean setCountImpl(Multiset<E> self, E element, int oldCount, int newCount) {
 checkNonnegative(oldCount, "oldCount");
 checkNonnegative(newCount, "newCount");
 if (self.count(element) == oldCount) {
  self.setCount(element, newCount);
  return true;
 } else {
  return false;
 }
}
origin: google/guava

public void testCollectionCreate() {
 Multiset<Color> ms = EnumMultiset.create(asList(Color.RED, Color.YELLOW, Color.RED));
 assertEquals(0, ms.count(Color.BLUE));
 assertEquals(1, ms.count(Color.YELLOW));
 assertEquals(2, ms.count(Color.RED));
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_ADD)
public void testAddOccurrences() {
 int originalCount = getMultiset().count(e0());
 assertEquals("old count", originalCount, getMultiset().add(e0(), 2));
 assertEquals("old count", originalCount + 2, getMultiset().count(e0()));
}
origin: google/guava

public void testCreateWithSize() {
 Multiset<String> multiset = HashMultiset.create(50);
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_ADD)
public void testAddSeveralTimes() {
 int originalCount = getMultiset().count(e0());
 assertEquals(originalCount, getMultiset().add(e0(), 2));
 assertTrue(getMultiset().add(e0()));
 assertEquals(originalCount + 3, getMultiset().add(e0(), 1));
 assertEquals(originalCount + 4, getMultiset().count(e0()));
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_ADD)
public void testAddOccurrencesZero() {
 int originalCount = getMultiset().count(e0());
 assertEquals("old count", originalCount, getMultiset().add(e0(), 0));
 expectUnchanged();
}
origin: google/guava

@CollectionSize.Require(SEVERAL)
public void testCount_3() {
 initThreeCopies();
 assertEquals("multiset.count(thriceContained) didn't return 3", 3, getMultiset().count(e0()));
}
origin: google/guava

@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsEntrySetIteratorRemove() {
 initThreeCopies();
 assertEquals(3, getMultiset().count(e0()));
 Iterator<Multiset.Entry<E>> entryItr = getMultiset().entrySet().iterator();
 Multiset.Entry<E> entry = entryItr.next();
 entryItr.remove();
 assertEquals(0, entry.getCount());
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_ADD)
public void testAddTooMany() {
 getMultiset().add(e3(), Integer.MAX_VALUE);
 try {
  getMultiset().add(e3());
  fail();
 } catch (IllegalArgumentException expected) {
 }
 assertEquals(Integer.MAX_VALUE, getMultiset().count(e3()));
 assertEquals(Integer.MAX_VALUE, getMultiset().size());
}
origin: google/guava

public void testCreateWithComparator() {
 Multiset<String> multiset = TreeMultiset.create(Collections.reverseOrder());
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[foo x 2, bar]", multiset.toString());
}
origin: google/guava

public void testCreateWithSize() {
 Multiset<String> multiset = LinkedHashMultiset.create(50);
 multiset.add("foo", 2);
 multiset.add("bar");
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[foo x 2, bar]", multiset.toString());
}
origin: google/guava

@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsEntrySetClear() {
 initThreeCopies();
 assertEquals(3, getMultiset().count(e0()));
 Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet());
 assertEquals(3, entry.getCount());
 getMultiset().entrySet().clear();
 assertEquals(0, entry.getCount());
}
origin: google/guava

@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsElementSetClear() {
 initThreeCopies();
 assertEquals(3, getMultiset().count(e0()));
 Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet());
 assertEquals(3, entry.getCount());
 getMultiset().elementSet().clear();
 assertEquals(0, entry.getCount());
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemoveZeroNoOp() {
 int originalCount = getMultiset().count(e0());
 assertEquals("old count", originalCount, getMultiset().remove(e0(), 0));
 expectUnchanged();
}
origin: google/guava

public void testCreateFromIterable() {
 Multiset<String> multiset = TreeMultiset.create(Arrays.asList("foo", "bar", "foo"));
 assertEquals(3, multiset.size());
 assertEquals(2, multiset.count("foo"));
 assertEquals("[bar, foo x 2]", multiset.toString());
}
origin: google/guava

@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_occurrences_present() {
 assertEquals(
   "multiset.remove(present, 2) didn't return the old count",
   1,
   getMultiset().remove(e0(), 2));
 assertFalse(
   "multiset contains present after multiset.remove(present, 2)",
   getMultiset().contains(e0()));
 assertEquals(0, getMultiset().count(e0()));
}
com.google.common.collectMultisetcount

Javadoc

Returns the number of occurrences of an element in this multiset (the count of the element). Note that for an Object#equals-based multiset, this gives the same result as Collections#frequency(which would presumably perform more poorly).

Note: the utility method Iterables#frequency generalizes this operation; it correctly delegates to this method when dealing with a multiset, but it can also accept any other iterable type.

Popular methods of Multiset

  • add
    Adds a number of occurrences of an element to this multiset. Note that if occurrences == 1, this met
  • elementSet
    Returns the set of distinct elements contained in this multiset. The element set is backed by the sa
  • entrySet
    Returns a view of the contents of this multiset, grouped into Multiset.Entry instances, each providi
  • remove
    Removes a number of occurrences of the specified element from this multiset. If the multiset contain
  • size
    Returns the total number of all occurrences of all elements in this multiset. Note: this method does
  • isEmpty
  • clear
  • contains
    Determines whether this multiset contains the specified element.This method refines Collection#conta
  • addAll
  • setCount
    Conditionally sets the count of an element to a new value, as described in #setCount(Object,int), pr
  • iterator
    Elements that occur multiple times in the multiset will appear multiple times in this iterator, thou
  • equals
    Compares the specified object with this multiset for equality. Returns true if the given object is a
  • iterator,
  • equals,
  • containsAll,
  • hashCode,
  • removeAll,
  • toString,
  • stream,
  • forEachEntry,
  • retainAll

Popular in Java

  • Reactive rest calls using spring rest template
  • findViewById (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • setRequestProperty (URLConnection)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now