Class Multisets.FilteredMultiset<E>

All Implemented Interfaces:
Multiset<E>, Iterable<E>, Collection<E>
Enclosing class:
Multisets

private static final class Multisets.FilteredMultiset<E> extends Multisets.ViewMultiset<E>
  • Field Details

  • Constructor Details

  • Method Details

    • iterator

      public UnmodifiableIterator<E> iterator()
      Description copied from interface: Multiset

      Elements that occur multiple times in the multiset will appear multiple times in this iterator, though not necessarily sequentially.

      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface Multiset<E>
      Overrides:
      iterator in class Multisets.ViewMultiset<E>
    • createElementSet

      Set<E> createElementSet()
      Description copied from class: AbstractMultiset
      Creates a new instance of this multiset's element set, which will be returned by AbstractMultiset.elementSet().
      Overrides:
      createElementSet in class AbstractMultiset<E>
    • elementIterator

      Iterator<E> elementIterator()
      Specified by:
      elementIterator in class AbstractMultiset<E>
    • createEntrySet

      Set<Multiset.Entry<E>> createEntrySet()
      Overrides:
      createEntrySet in class AbstractMultiset<E>
    • entryIterator

      Iterator<Multiset.Entry<E>> entryIterator()
      Specified by:
      entryIterator in class AbstractMultiset<E>
    • count

      public int count(@CheckForNull Object element)
      Description copied from interface: Multiset
      Returns the number of occurrences of an element in this multiset (the count of the element). Note that for an Object.equals(java.lang.Object)-based multiset, this gives the same result as Collections.frequency(java.util.Collection<?>, java.lang.Object) (which would presumably perform more poorly).

      Note: the utility method Iterables.frequency(java.lang.Iterable<?>, java.lang.Object) generalizes this operation; it correctly delegates to this method when dealing with a multiset, but it can also accept any other iterable type.

      Parameters:
      element - the element to count occurrences of
      Returns:
      the number of occurrences of the element in this multiset; possibly zero but never negative
    • add

      public int add(E element, int occurrences)
      Description copied from interface: Multiset
      Adds a number of occurrences of an element to this multiset. Note that if occurrences == 1, this method has the identical effect to Multiset.add(Object). This method is functionally equivalent (except in the case of overflow) to the call addAll(Collections.nCopies(element, occurrences)), which would presumably perform much more poorly.
      Specified by:
      add in interface Multiset<E>
      Overrides:
      add in class AbstractMultiset<E>
      Parameters:
      element - the element to add occurrences of; may be null only if explicitly allowed by the implementation
      occurrences - the number of occurrences of the element to add. May be zero, in which case no change will be made.
      Returns:
      the count of the element before the operation; possibly zero
    • remove

      public int remove(@CheckForNull Object element, int occurrences)
      Description copied from interface: Multiset
      Removes a number of occurrences of the specified element from this multiset. If the multiset contains fewer than this number of occurrences to begin with, all occurrences will be removed. Note that if occurrences == 1, this is functionally equivalent to the call remove(element).
      Specified by:
      remove in interface Multiset<E>
      Overrides:
      remove in class AbstractMultiset<E>
      Parameters:
      element - the element to conditionally remove occurrences of
      occurrences - the number of occurrences of the element to remove. May be zero, in which case no change will be made.
      Returns:
      the count of the element before the operation; possibly zero