Codota Logo
Multiset.count
Code IndexAdd Codota 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)

  • Common ways to obtain Multiset
private void myMethod () {
Multiset m =
  • Codota IconMultimap fromMultimap;fromMultimap.keys()
  • Codota Iconnew Keys()
  • Codota Iconnew Multimaps.Keys<K, V>(this)
  • Smart code suggestions by Codota
}
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

  • Parsing JSON documents to java classes using gson
  • requestLocationUpdates (LocationManager)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • Menu (java.awt)
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now