Class AbstractMultiset<T>
java.lang.Object
org.javimmutable.collections.common.AbstractMultiset<T>
- All Implemented Interfaces:
Serializable
,Iterable<T>
,ICollection<T>
,IMultiset<T>
,InvariantCheckable
,ISet<T>
,IStreamable<T>
,Mapped<T,
,T> SplitableIterable<T>
- Direct Known Subclasses:
HashMultiset
,OrderedMultiset
,TreeMultiset
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks invariants of implementing class.boolean
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> values) 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.Implemented by derived classes to create a new instance of the appropriate class.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 subtractBy) Removes count number of occurrences of value from the multiset.Implemented by derived classes to create a new empty mutable Map that operates in the same way as this multiset's underlying immutable Map.entries()
Stream iterates through each Entry, that contains a unique value and the count of occurrences.boolean
getSet()
int
int
hashCode()
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.boolean
isEmpty()
iterator()
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.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()
toString()
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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.javimmutable.collections.ICollection
isNonEmpty
Methods inherited from interface org.javimmutable.collections.IMultiset
deleteAll, multisetCollector
Methods inherited from interface org.javimmutable.collections.ISet
find, get, getValueOr, reject, select, setCollector
Methods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, stream
Methods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Field Details
-
map
-
occurrences
protected final int occurrences
-
-
Constructor Details
-
AbstractMultiset
-
-
Method Details
-
insert
Description copied from interface:IMultiset
Adds one occurrence of value to the multiset. -
insert
Description copied from interface:IMultiset
Adds count number of occurrences of value to the multiset. Count must be greater than or equal to zero. -
contains
Description copied from interface:IMultiset
Determines if the multiset contains at least one occurrence of the specified value -
containsAtLeast
Description copied from interface:IMultiset
Determines if the multiset contains at least count occurrences of value.- Specified by:
containsAtLeast
in interfaceIMultiset<T>
- Parameters:
value
- value to check forcount
- number of occurrences checked for- Returns:
- true if thsi multiset contains at least count occurrences of value
-
containsAll
Description copied from interface:IMultiset
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 interfaceIMultiset<T>
- Specified by:
containsAll
in interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains all values
-
containsAll
Description copied from interface:IMultiset
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 interfaceIMultiset<T>
- Specified by:
containsAll
in interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains all values
-
containsAllOccurrences
Description copied from interface:IMultiset
Determines if the multiset contains every occurrence of all the values in other. If other is empty, returns true. Slow operation.- Specified by:
containsAllOccurrences
in interfaceIMultiset<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains all occurrences
-
containsAllOccurrences
Description copied from interface:IMultiset
Determines if the multiset contains every occurrence of all the values in other. If other is empty, returns true. Slow operation.- Specified by:
containsAllOccurrences
in interfaceIMultiset<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains all occurrences
-
containsAllOccurrences
Description copied from interface:IMultiset
Determines if the multiset contains every occurrence of all the values in other. If other is empty, returns true.- Specified by:
containsAllOccurrences
in interfaceIMultiset<T>
- Parameters:
values
- contains values to be checked for- Returns:
- true if this multiset contains all occurrences
-
containsAny
Description copied from interface:IMultiset
Determines if the multiset and other have at least one value in common. Returns false if other is empty.- Specified by:
containsAny
in interfaceIMultiset<T>
- Specified by:
containsAny
in interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains a value
-
containsAny
Description copied from interface:IMultiset
Determines if the multiset and other have at least one value in common. Returns false if other is empty.- Specified by:
containsAny
in interfaceIMultiset<T>
- Specified by:
containsAny
in interfaceISet<T>
- Parameters:
other
- contains values to be checked for- Returns:
- true if this multiset contains a value
-
delete
Description copied from interface:IMultiset
Removes every occurrence of value from the multiset. -
deleteOccurrence
Description copied from interface:IMultiset
Removes one occurrence of value from the multiset.- Specified by:
deleteOccurrence
in interfaceIMultiset<T>
- Parameters:
value
- value to remove- Returns:
- new multiset reflecting the change
-
deleteOccurrence
Description copied from interface:IMultiset
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.- Specified by:
deleteOccurrence
in interfaceIMultiset<T>
- Parameters:
value
- value to removesubtractBy
- number of occurrences to remove- Returns:
- new multiset reflecting the change
-
deleteAll
Description copied from interface:IMultiset
Removes all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other. -
deleteAll
Description copied from interface:IMultiset
Removes all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other. -
deleteAllOccurrences
Description copied from interface:IMultiset
Removes each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.- Specified by:
deleteAllOccurrences
in interfaceIMultiset<T>
- Parameters:
other
- contains occurrences to delete- Returns:
- new multiset reflecting the change
-
deleteAllOccurrences
Description copied from interface:IMultiset
Removes each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.- Specified by:
deleteAllOccurrences
in interfaceIMultiset<T>
- Parameters:
other
- contains occurrences to delete- Returns:
- new multiset reflecting the change
-
deleteAllOccurrences
Description copied from interface:IMultiset
Removes each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.- Specified by:
deleteAllOccurrences
in interfaceIMultiset<T>
- Parameters:
other
- contains occurrences to delete- Returns:
- new multiset reflecting the change
-
insertAll
Description copied from interface:IMultiset
Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
insertAll
Description copied from interface:IMultiset
Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
insertAll
Description copied from interface:IMultiset
Adds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
union
Description copied from interface:IMultiset
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
Description copied from interface:IMultiset
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
Description copied from interface:IMultiset
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. -
intersection
Description copied from interface:IMultiset
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 interfaceIMultiset<T>
- Specified by:
intersection
in interfaceISet<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultiset
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 interfaceIMultiset<T>
- Specified by:
intersection
in interfaceISet<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultiset
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 interfaceIMultiset<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultiset
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 interfaceIMultiset<T>
- Specified by:
intersection
in interfaceISet<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultiset
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 interfaceIMultiset<T>
- Specified by:
intersection
in interfaceISet<T>
- Parameters:
other
- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
count
Description copied from interface:IMultiset
Returns the number of occurrences associated with the specified value. If the value is not contained in the multiset, 0 is returned. -
setCount
Description copied from interface:IMultiset
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). -
create
Implemented by derived classes to create a new instance of the appropriate class.- Parameters:
map
- base map for new multisetoccurrences
- total occurrences in map- Returns:
- new multiset built from map
-
emptyMutableMap
Implemented by derived classes to create a new empty mutable Map that operates in the same way as this multiset's underlying immutable Map.- Returns:
- new empty Counter
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceICollection<T>
- Returns:
- true only if collection contains no values
-
size
public int size() -
occurrenceCount
public int occurrenceCount()- Specified by:
occurrenceCount
in interfaceIMultiset<T>
- Returns:
- the total number of occurrences in the multiset. Same as the number of items in occurrences.iterator().
-
getSet
-
iterator
Description copied from interface:IStreamable
Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator. This is necessary to allow composition of new objects from methods like keys() and values().- Specified by:
iterator
in interfaceIStreamable<T>
- Specified by:
iterator
in interfaceIterable<T>
- Specified by:
iterator
in interfaceSplitableIterable<T>
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristics
in interfaceIStreamable<T>
- Returns:
- characteristics value used when creating Spliterators
-
entries
Description copied from interface:IMultiset
Stream iterates through each Entry, that contains a unique value and the count of occurrences. -
occurrences
Description copied from interface:IMultiset
IStreamable that iterates through each occurrence in the multiset the correct number of times.- Specified by:
occurrences
in interfaceIMultiset<T>
- Returns:
- IStreamable that behaves as if multiset was a list
-
hashCode
public int hashCode() -
equals
-
toString
-
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckable
Checks invariants of implementing class.- Specified by:
checkInvariants
in interfaceInvariantCheckable
-