Class Multimaps.Keys<K,​V>

    • Constructor Detail

    • Method Detail

      • spliterator

        public java.util.Spliterator<K> spliterator()
      • forEach

        public void forEach​(java.util.function.Consumer<? super K> consumer)
        Description copied from interface: Multiset

        Elements that occur multiple times in the multiset will be passed to the Consumer correspondingly many times, though not necessarily sequentially.

      • size

        public int size()
        Description copied from interface: Multiset
        Returns the total number of all occurrences of all elements in this multiset.

        Note: this method does not return the number of distinct elements in the multiset, which is given by entrySet().size().

        Specified by:
        size in interface java.util.Collection<K>
        Specified by:
        size in interface Multiset<K>
        Specified by:
        size in class java.util.AbstractCollection<K>
      • contains

        public boolean contains​(@CheckForNull
                                java.lang.Object element)
        Description copied from interface: Multiset
        Determines whether this multiset contains the specified element.

        This method refines Collection.contains(java.lang.Object) to further specify that it may not throw an exception in response to element being null or of the wrong type.

        Specified by:
        contains in interface java.util.Collection<K>
        Specified by:
        contains in interface Multiset<K>
        Overrides:
        contains in class AbstractMultiset<K>
        Parameters:
        element - the element to check for
        Returns:
        true if this multiset contains at least one occurrence of the element
      • iterator

        public java.util.Iterator<K> 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 java.util.Collection<K>
        Specified by:
        iterator in interface java.lang.Iterable<K>
        Specified by:
        iterator in interface Multiset<K>
        Specified by:
        iterator in class java.util.AbstractCollection<K>
      • count

        public int count​(@CheckForNull
                         java.lang.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
      • remove

        public int remove​(@CheckForNull
                          java.lang.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<K>
        Overrides:
        remove in class AbstractMultiset<K>
        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
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<K>
        Specified by:
        clear in class AbstractMultiset<K>
      • elementSet

        public java.util.Set<K> elementSet()
        Description copied from interface: Multiset
        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().

        Specified by:
        elementSet in interface Multiset<K>
        Overrides:
        elementSet in class AbstractMultiset<K>
        Returns:
        a view of the set of distinct elements in this multiset