Package org.javimmutable.collections
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
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 Summary
Modifier and TypeMethodDescriptionboolean
Determines if the multiset contains at least one occurrence of the specified valueboolean
containsAll
(Iterable<? extends T> other) Determines if the multiset contains every value (but not necessarily the same number of occurrences of each value) in other.boolean
containsAll
(Iterator<? extends T> other) Determines if the multiset contains every value (but not necessarily the same number of occurrences of each value) in other.boolean
containsAllOccurrences
(Iterable<? extends T> other) Determines if the multiset contains every occurrence of all the values in other.boolean
containsAllOccurrences
(Iterator<? extends T> other) Determines if the multiset contains every occurrence of all the values in other.boolean
containsAllOccurrences
(IMultiset<? extends T> other) Determines if the multiset contains every occurrence of all the values in other.boolean
containsAny
(Iterable<? extends T> other) Determines if the multiset and other have at least one value in common.boolean
containsAny
(Iterator<? extends T> other) Determines if the multiset and other have at least one value in common.boolean
containsAtLeast
(T value, int count) Determines if the multiset contains at least count occurrences of value.int
Returns the number of occurrences associated with the specified value.Removes every occurrence of value from the multiset.Removes all occurrences of each value in other from the multiset.Removes all occurrences of each value in other from the multiset.deleteAllOccurrences
(Iterable<? extends T> other) Removes each occurrence in other from the multiset.deleteAllOccurrences
(Iterator<? extends T> other) Removes each occurrence in other from the multiset.deleteAllOccurrences
(IMultiset<? extends T> other) Removes each occurrence in other from the multiset.deleteOccurrence
(T value) Removes one occurrence of value from the multiset.deleteOccurrence
(T value, int count) Removes count number of occurrences of value from the multiset.entries()
Stream iterates through each Entry, that contains a unique value and the count of occurrences.Adds one occurrence of value to the multiset.Adds count number of occurrences of value to the multiset.Adds each occurrence in values to the multiset.Adds each occurrence in values to the multiset.Adds each occurrence in values to the multiset.intersection
(Iterable<? extends T> other) Creates a new multiset with the occurrences that are in both other and this.intersection
(Iterator<? extends T> other) Creates a new multiset with the occurrences that are in both other and this.intersection
(Set<? extends T> other) Creates a new multiset with the occurrences that are in both other and this.intersection
(IMultiset<? extends T> other) Creates a new multiset with the occurrences that are in both other and this.intersection
(ISet<? extends T> other) Creates a new multiset with the occurrences that are in both other and this.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.int
IStreamable that iterates through each occurrence in the multiset the correct number of times.Manually sets the number of occurrences associated with the specified value.int
size()
Combines all occurrences from other and the multiset.Combines all occurrences from other and the multiset.Combines all occurrences from other and the multiset.Methods inherited from interface org.javimmutable.collections.ICollection
isEmpty, isNonEmpty
Methods inherited from interface org.javimmutable.collections.InvariantCheckable
checkInvariants
Methods inherited from interface org.javimmutable.collections.ISet
find, get, getSet, getValueOr, reject, select, setCollector
Methods inherited from interface org.javimmutable.collections.IStreamable
getSpliteratorCharacteristics, iterator, parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Method Details
-
insert
Adds one occurrence of value to the multiset. -
insert
Adds count number of occurrences of value to the multiset. Count must be greater than or equal to zero.- Parameters:
value
- value to addcount
- number of occurrences added- Returns:
- new multiset reflecting the change
-
contains
Determines if the multiset contains at least one occurrence of the specified value -
containsAtLeast
Determines if the multiset contains at least count occurrences of value.- Parameters:
value
- value to check forcount
- number of occurrences checked for- Returns:
- true if thsi multiset contains at least count occurrences of value
-
containsAll
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 interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains all values
-
containsAll
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 interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains all values
-
containsAllOccurrences
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
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
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
Determines if the multiset and other have at least one value in common. Returns false if other is empty.- Specified by:
containsAny
in interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains a value
-
containsAny
Determines if the multiset and other have at least one value in common. Returns false if other is empty.- Specified by:
containsAny
in interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains a value
-
delete
Removes every occurrence of value from the multiset. -
deleteOccurrence
Removes one occurrence of value from the multiset.- Parameters:
value
- value to remove- Returns:
- new multiset reflecting the change
-
deleteOccurrence
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 removecount
- number of occurrences to remove- Returns:
- new multiset reflecting the change
-
deleteAll
-
deleteAll
Removes all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other. -
deleteAll
Removes all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other. -
deleteAllOccurrences
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
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
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
Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
insertAll
Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
insertAll
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
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. -
union
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. -
union
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
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 interfaceISet<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
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 interfaceISet<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
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
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 interfaceISet<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
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 interfaceISet<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
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
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
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 addcount
- new number of occurrences for value- Returns:
- new multiset reflecting the change
-
size
int size()- Specified by:
size
in interfaceICollection<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
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.
-