Interface IMultiset<T>

All Superinterfaces:
ICollection<T>, InvariantCheckable, ISet<T>, IStreamable<T>, Iterable<T>, Mapped<T,T>, Serializable, SplitableIterable<T>
All Known Implementing Classes:
AbstractMultiset, HashMultiset, OrderedMultiset, TreeMultiset

@Immutable public interface IMultiset<T> extends ISet<T>, Serializable
Keeps a set of distinct values, as well as the count corresponding to each value. Can iterate through the multiset with the correct number of occurrences per value.
  • Method Details

    • insert

      @Nonnull IMultiset<T> insert(@Nonnull T value)
      Adds one occurrence of value to the multiset.
      Specified by:
      insert in interface ICollection<T>
      Specified by:
      insert in interface ISet<T>
      Parameters:
      value - value to add
      Returns:
      new multiset reflecting the change
    • insert

      @Nonnull IMultiset<T> insert(@Nonnull T value, int count)
      Adds count number of occurrences of value to the multiset. Count must be greater than or equal to zero.
      Parameters:
      value - value to add
      count - number of occurrences added
      Returns:
      new multiset reflecting the change
    • contains

      boolean contains(@Nullable T value)
      Determines if the multiset contains at least one occurrence of the specified value
      Specified by:
      contains in interface ISet<T>
      Parameters:
      value - value to check for
      Returns:
      true if this multiset contains the value
    • containsAtLeast

      boolean containsAtLeast(@Nullable T value, int count)
      Determines if the multiset contains at least count occurrences of value.
      Parameters:
      value - value to check for
      count - number of occurrences checked for
      Returns:
      true if thsi multiset contains at least count occurrences of value
    • containsAll

      boolean containsAll(@Nonnull Iterable<? extends T> other)
      Determines if the multiset contains every value (but not necessarily the same number of occurrences of each value) in other. If other is empty, returns true. Synonymous to calling contains() on each element of other.
      Specified by:
      containsAll in interface ISet<T>
      Parameters:
      other - contains values to be checked for
      Returns:
      true if this multiset contains all values
    • containsAll

      boolean containsAll(@Nonnull Iterator<? extends T> other)
      Determines if the multiset contains every value (but not necessarily the same number of occurrences of each value) in other. If other is empty, returns true. Synonymous to calling contains() on each element of other.
      Specified by:
      containsAll in interface ISet<T>
      Parameters:
      other - contains values to be checked for
      Returns:
      true if this multiset contains all values
    • containsAllOccurrences

      boolean containsAllOccurrences(@Nonnull Iterable<? extends T> other)
      Determines if the multiset contains every occurrence of all the values in other. If other is empty, returns true. Slow operation.
      Parameters:
      other - contains values to be checked for
      Returns:
      true if this multiset contains all occurrences
    • containsAllOccurrences

      boolean containsAllOccurrences(@Nonnull Iterator<? extends T> other)
      Determines if the multiset contains every occurrence of all the values in other. If other is empty, returns true. Slow operation.
      Parameters:
      other - contains values to be checked for
      Returns:
      true if this multiset contains all occurrences
    • containsAllOccurrences

      boolean containsAllOccurrences(@Nonnull IMultiset<? extends T> other)
      Determines if the multiset contains every occurrence of all the values in other. If other is empty, returns true.
      Parameters:
      other - contains values to be checked for
      Returns:
      true if this multiset contains all occurrences
    • containsAny

      boolean containsAny(@Nonnull Iterable<? extends T> other)
      Determines if the multiset and other have at least one value in common. Returns false if other is empty.
      Specified by:
      containsAny in interface ISet<T>
      Parameters:
      other - contains values to be checked for
      Returns:
      true if this multiset contains a value
    • containsAny

      boolean containsAny(@Nonnull Iterator<? extends T> other)
      Determines if the multiset and other have at least one value in common. Returns false if other is empty.
      Specified by:
      containsAny in interface ISet<T>
      Parameters:
      other - contains values to be checked for
      Returns:
      true if this multiset contains a value
    • delete

      @Nonnull IMultiset<T> delete(@Nonnull T value)
      Removes every occurrence of value from the multiset.
      Specified by:
      delete in interface ISet<T>
      Parameters:
      value - value to remove
      Returns:
      new multiset reflecting the change
    • deleteOccurrence

      @Nonnull IMultiset<T> deleteOccurrence(@Nonnull T value)
      Removes one occurrence of value from the multiset.
      Parameters:
      value - value to remove
      Returns:
      new multiset reflecting the change
    • deleteOccurrence

      @Nonnull IMultiset<T> deleteOccurrence(@Nonnull T value, int count)
      Removes count number of occurrences of value from the multiset. If there are fewer than count occurrences in the multimap, then all the occurrences that do exist are deleted. Count must be greater than or equal to zero.
      Parameters:
      value - value to remove
      count - number of occurrences to remove
      Returns:
      new multiset reflecting the change
    • deleteAll

      @Nonnull IMultiset<T> deleteAll()
      Specified by:
      deleteAll in interface ICollection<T>
      Specified by:
      deleteAll in interface ISet<T>
      Returns:
      an equivalent collection with no values
    • deleteAll

      @Nonnull IMultiset<T> deleteAll(@Nonnull Iterable<? extends T> other)
      Removes all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other.
      Specified by:
      deleteAll in interface ISet<T>
      Parameters:
      other - contains values to delete
      Returns:
      new multiset reflecting the change
    • deleteAll

      @Nonnull IMultiset<T> deleteAll(@Nonnull Iterator<? extends T> other)
      Removes all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other.
      Specified by:
      deleteAll in interface ISet<T>
      Parameters:
      other - contains values to delete
      Returns:
      new multiset reflecting the change
    • deleteAllOccurrences

      @Nonnull IMultiset<T> deleteAllOccurrences(@Nonnull Iterable<? extends T> other)
      Removes each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.
      Parameters:
      other - contains occurrences to delete
      Returns:
      new multiset reflecting the change
    • deleteAllOccurrences

      @Nonnull IMultiset<T> deleteAllOccurrences(@Nonnull Iterator<? extends T> other)
      Removes each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.
      Parameters:
      other - contains occurrences to delete
      Returns:
      new multiset reflecting the change
    • deleteAllOccurrences

      @Nonnull IMultiset<T> deleteAllOccurrences(@Nonnull IMultiset<? extends T> other)
      Removes each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.
      Parameters:
      other - contains occurrences to delete
      Returns:
      new multiset reflecting the change
    • insertAll

      @Nonnull IMultiset<T> insertAll(@Nonnull Iterable<? extends T> values)
      Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values.
      Specified by:
      insertAll in interface ICollection<T>
      Specified by:
      insertAll in interface ISet<T>
      Parameters:
      values - contains occurrences to be added
      Returns:
      new multiset reflecting the change
    • insertAll

      @Nonnull IMultiset<T> insertAll(@Nonnull Iterator<? extends T> values)
      Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values.
      Specified by:
      insertAll in interface ICollection<T>
      Specified by:
      insertAll in interface ISet<T>
      Parameters:
      values - contains occurrences to be added
      Returns:
      new multiset reflecting the change
    • insertAll

      @Nonnull IMultiset<T> insertAll(@Nonnull IMultiset<? extends T> values)
      Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values.
      Parameters:
      values - contains occurrences to be added
      Returns:
      new multiset reflecting the change
    • union

      @Nonnull IMultiset<T> union(@Nonnull Iterable<? extends T> other)
      Combines all occurrences from other and the multiset. If only the multiset or other contains a value, that value's count is preserved in the new multiset. If both contain a value, the greater count is used. Slow operation.
      Specified by:
      union in interface ISet<T>
      Parameters:
      other - contains values to union with this multiset
      Returns:
      new multiset reflecting the changes
    • union

      @Nonnull IMultiset<T> union(@Nonnull Iterator<? extends T> other)
      Combines all occurrences from other and the multiset. If only the multiset or other contains a value, that value's count is preserved in the new multiset. If both contain a value, the greater count is used. Slow operation.
      Specified by:
      union in interface ISet<T>
      Parameters:
      other - contains values to union with this multiset
      Returns:
      new multiset reflecting the changes
    • union

      @Nonnull IMultiset<T> union(@Nonnull IMultiset<? extends T> other)
      Combines all occurrences from other and the multiset. If only the multiset or other contains a value, that value's count is preserved in the new multiset. If both contain a value, the greater count is used.
      Parameters:
      other - contains values to union with this multiset
      Returns:
      new multiset reflecting the changes
    • intersection

      @Nonnull IMultiset<T> intersection(@Nonnull Iterable<? extends T> other)
      Creates a new multiset with the occurrences that are in both other and this. If neither the multiset nor other contains a value, it is removed. If both contain a value, the lesser count is used. Slow operation.
      Specified by:
      intersection in interface ISet<T>
      Parameters:
      other - contains values to intersect with this multiset
      Returns:
      new multiset reflecting the change
    • intersection

      @Nonnull IMultiset<T> intersection(@Nonnull Iterator<? extends T> other)
      Creates a new multiset with the occurrences that are in both other and this. If neither the multiset nor other contains a value, it is removed. If both contain a value, the lesser count is used. Slow operation.
      Specified by:
      intersection in interface ISet<T>
      Parameters:
      other - contains values to intersect with this multiset
      Returns:
      new multiset reflecting the change
    • intersection

      @Nonnull IMultiset<T> intersection(@Nonnull IMultiset<? extends T> other)
      Creates a new multiset with the occurrences that are in both other and this. If neither the multiset nor other contains a value, it is removed. If both contain a value, the lesser count is used.
      Parameters:
      other - contains values to intersect with this multiset
      Returns:
      new multiset reflecting the change
    • intersection

      @Nonnull IMultiset<T> intersection(@Nonnull ISet<? extends T> other)
      Creates a new multiset with the occurrences that are in both other and this. If neither the multiset nor other contains a value, it is removed. If both contain a value, the lesser count is used.
      Specified by:
      intersection in interface ISet<T>
      Parameters:
      other - contains values to intersect with this multiset
      Returns:
      new multiset reflecting the change
    • intersection

      @Nonnull IMultiset<T> intersection(@Nonnull Set<? extends T> other)
      Creates a new multiset with the occurrences that are in both other and this. If neither the multiset nor other contains a value, it is removed. If both contain a value, the lesser count is used.
      Specified by:
      intersection in interface ISet<T>
      Parameters:
      other - contains values to intersect with this multiset
      Returns:
      new multiset reflecting the change
    • entries

      Stream iterates through each Entry, that contains a unique value and the count of occurrences.
      Returns:
      IStreamable of IMap.Entries
    • occurrences

      @Nonnull IStreamable<T> occurrences()
      IStreamable that iterates through each occurrence in the multiset the correct number of times.
      Returns:
      IStreamable that behaves as if multiset was a list
    • count

      int count(@Nonnull T value)
      Returns the number of occurrences associated with the specified value. If the value is not contained in the multiset, 0 is returned.
      Parameters:
      value - value to check for
      Returns:
      number of occurrences
    • setCount

      @Nonnull IMultiset<T> setCount(@Nonnull T value, int count)
      Manually sets the number of occurrences associated with the specified value. Count must be greater than or equal to zero. If count == 0, is synonymous to delete(value). If value is not currently in the multiset, is equivalent to insert(value, count).
      Parameters:
      value - value to add
      count - new number of occurrences for value
      Returns:
      new multiset reflecting the change
    • size

      int size()
      Specified by:
      size in interface ICollection<T>
      Returns:
      total number of unique values in the multiset. Same as the number of items in iterator() and entries().iterator().
    • occurrenceCount

      int occurrenceCount()
      Returns:
      the total number of occurrences in the multiset. Same as the number of items in occurrences.iterator().
    • multisetCollector

      @Nonnull default java.util.stream.Collector<T,?,IMultiset<T>> multisetCollector()
      Returns a Collector that creates a multiset of the same type as this containing all of the collected values inserted over whatever starting values this already contained.