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

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

Best Java code snippets using com.google.common.collect.Multiset.elementSet (Showing top 20 results out of 963)

origin: google/guava

/** An implementation of {@link Multiset#removeAll}. */
static boolean removeAllImpl(Multiset<?> self, Collection<?> elementsToRemove) {
 Collection<?> collection =
   (elementsToRemove instanceof Multiset)
     ? ((Multiset<?>) elementsToRemove).elementSet()
     : elementsToRemove;
 return self.elementSet().removeAll(collection);
}
origin: google/guava

/** An implementation of {@link Multiset#retainAll}. */
static boolean retainAllImpl(Multiset<?> self, Collection<?> elementsToRetain) {
 checkNotNull(elementsToRetain);
 Collection<?> collection =
   (elementsToRetain instanceof Multiset)
     ? ((Multiset<?>) elementsToRetain).elementSet()
     : elementsToRetain;
 return self.elementSet().retainAll(collection);
}
origin: google/guava

/**
 * Returns the expected number of distinct elements given the specified elements. The number of
 * distinct elements is only computed if {@code elements} is an instance of {@code Multiset};
 * otherwise the default value of 11 is returned.
 */
static int inferDistinctElements(Iterable<?> elements) {
 if (elements instanceof Multiset) {
  return ((Multiset<?>) elements).elementSet().size();
 }
 return 11; // initial capacity will be rounded up to 16
}
origin: google/guava

@Override
public Set<E> create(Object... elements) {
 Object[] duplicated = new Object[elements.length * 2];
 for (int i = 0; i < elements.length; i++) {
  duplicated[i] = elements[i];
  duplicated[i + elements.length] = elements[i];
 }
 return ((Multiset<E>) gen.create(duplicated)).elementSet();
}
origin: google/guava

@Override
public Set<E> elementSet() {
 synchronized (mutex) {
  if (elementSet == null) {
   elementSet = typePreservingSet(delegate().elementSet(), mutex);
  }
  return elementSet;
 }
}
origin: google/guava

@Override
public Set<E> elementSet() {
 return delegate().elementSet();
}
origin: google/guava

@Override
public Set<N> successors() {
 return Collections.unmodifiableSet(successorsMultiset().elementSet());
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_occurrences_absent() {
 int distinct = getMultiset().elementSet().size();
 assertEquals("multiset.remove(absent, 0) didn't return 0", 0, getMultiset().remove(e3(), 2));
 assertEquals(distinct, getMultiset().elementSet().size());
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetClear() {
 getMultiset().elementSet().clear();
 assertEmpty(getMultiset());
}
origin: google/guava

@CollectionSize.Require(absent = ZERO)
public void testElementSet_contains() {
 assertTrue(
   "multiset.elementSet().contains(present) returned false",
   getMultiset().elementSet().contains(e0()));
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetRemoveAbsent() {
 Set<E> elementSet = getMultiset().elementSet();
 assertFalse(elementSet.remove(e3()));
 expectUnchanged();
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_ADD)
public void testElementSetReflectsAddAbsent() {
 Set<E> elementSet = getMultiset().elementSet();
 assertFalse(elementSet.contains(e3()));
 getMultiset().add(e3(), 4);
 assertTrue(elementSet.contains(e3()));
}
origin: google/guava

 @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
 public void testElementSetSerialization() {
  Set<E> expected = getMultiset().elementSet();
  assertEquals(expected, SerializableTester.reserialize(expected));
 }
}
origin: google/guava

@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetReflectsRemove() {
 Set<E> elementSet = getMultiset().elementSet();
 assertTrue(elementSet.contains(e0()));
 getMultiset().removeAll(Collections.singleton(e0()));
 assertFalse(elementSet.contains(e0()));
}
origin: google/guava

 private static long worstCaseQueryOperations(Multiset<?> multiset, CallsCounter counter) {
  long worstCalls = 0;
  for (Object k : multiset.elementSet()) {
   counter.zero();
   int unused = multiset.count(k);
   worstCalls = Math.max(worstCalls, counter.total());
  }
  return worstCalls;
 }
}
origin: google/guava

public void testSerialization_elementSet() {
 Multiset<String> c = ImmutableSortedMultiset.of("a", "b", "a");
 Collection<String> copy = SerializableTester.reserializeAndAssert(c.elementSet());
 assertThat(copy).containsExactly("a", "b").inOrder();
}
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

@GwtIncompatible // SerializableTester
public void testSerialization_elementSet() {
 Multiset<String> c = ImmutableMultiset.of("a", "b", "a");
 Collection<String> copy = LenientSerializableTester.reserializeAndAssertLenient(c.elementSet());
 assertThat(copy).containsExactly("a", "b").inOrder();
}
origin: google/guava

@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetRemoveDuplicatePropagatesToMultiset() {
 initThreeCopies();
 int size = getNumElements();
 int expectedSize = size - getMultiset().count(e0());
 Set<E> elementSet = getMultiset().elementSet();
 assertTrue(elementSet.remove(e0()));
 assertEmpty(getMultiset());
 assertEquals(expectedSize, getMultiset().size());
}
origin: google/guava

@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testElementSetRemovePropagatesToMultiset() {
 Set<E> elementSet = getMultiset().elementSet();
 int size = getNumElements();
 int expectedSize = size - getMultiset().count(e0());
 assertTrue(elementSet.remove(e0()));
 assertFalse(getMultiset().contains(e0()));
 assertEquals(expectedSize, getMultiset().size());
}
com.google.common.collectMultisetelementSet

Javadoc

Returns the set of distinct elements contained in this multiset. The element set is backed by the same data as the multiset, so any change to either is immediately reflected in the other. The order of the elements in the element set is unspecified.

If the element set supports any removal operations, these necessarily cause all occurrences of the removed element(s) to be removed from the multiset. Implementations are not expected to support the add operations, although this is possible.

A common use for the element set is to find the number of distinct elements in the multiset: elementSet().size().

Popular methods of Multiset

  • add
    Adds a number of occurrences of an element to this multiset. Note that if occurrences == 1, this met
  • count
    Returns the number of occurrences of an element in this multiset (thecount of the element). Note tha
  • 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

  • Making http requests using okhttp
  • findViewById (Activity)
  • getSystemService (Context)
  • runOnUiThread (Activity)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Reference (javax.naming)
  • JCheckBox (javax.swing)
  • Best IntelliJ plugins
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