Class ImmutableMultimap.Keys

All Implemented Interfaces:
Multiset<K>, Serializable, Iterable<K>, Collection<K>
Enclosing class:
ImmutableMultimap<K,V>

class ImmutableMultimap.Keys extends ImmutableMultiset<K>
  • Constructor Details

    • Keys

      Keys()
  • Method Details

    • contains

      public boolean contains(@CheckForNull Object object)
      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 Collection<K>
      Specified by:
      contains in interface Multiset<K>
      Overrides:
      contains in class ImmutableMultiset<K>
      Parameters:
      object - the element to check for
      Returns:
      true if this multiset contains at least one occurrence of the element
    • 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
    • elementSet

      public ImmutableSet<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>
      Specified by:
      elementSet in class ImmutableMultiset<K>
      Returns:
      a view of the set of distinct elements in this multiset
    • 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 Collection<K>
      Specified by:
      size in interface Multiset<K>
      Specified by:
      size in class AbstractCollection<K>
    • getEntry

      Multiset.Entry<K> getEntry(int index)
      Specified by:
      getEntry in class ImmutableMultiset<K>
    • isPartialView

      boolean isPartialView()
      Description copied from class: ImmutableCollection
      Returns true if this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods. This is generally used to determine whether copyOf implementations should make an explicit copy to avoid memory leaks.
      Specified by:
      isPartialView in class ImmutableCollection<K>
    • writeReplace

      Object writeReplace()
      Overrides:
      writeReplace in class ImmutableMultiset<K>
    • readObject

      private void readObject(ObjectInputStream stream) throws InvalidObjectException
      Throws:
      InvalidObjectException