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
FieldsModifier and TypeFieldDescriptionprotected final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks invariants of implementing class.booleanDetermines if the multiset contains at least one occurrence of the specified valuebooleancontainsAll(Iterable<? extends T> other) Determines if the multiset contains every value (but not necessarily the same number of occurrences of each value) in other.booleancontainsAll(Iterator<? extends T> other) Determines if the multiset contains every value (but not necessarily the same number of occurrences of each value) in other.booleancontainsAllOccurrences(Iterable<? extends T> other) Determines if the multiset contains every occurrence of all the values in other.booleancontainsAllOccurrences(Iterator<? extends T> other) Determines if the multiset contains every occurrence of all the values in other.booleancontainsAllOccurrences(IMultiset<? extends T> values) Determines if the multiset contains every occurrence of all the values in other.booleancontainsAny(Iterable<? extends T> other) Determines if the multiset and other have at least one value in common.booleancontainsAny(Iterator<? extends T> other) Determines if the multiset and other have at least one value in common.booleancontainsAtLeast(T value, int count) Determines if the multiset contains at least count occurrences of value.intReturns 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.booleangetSet()intinthashCode()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.booleanisEmpty()iterator()Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.intIStreamable that iterates through each occurrence in the multiset the correct number of times.Manually sets the number of occurrences associated with the specified value.intsize()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, waitMethods inherited from interface org.javimmutable.collections.ICollection
isNonEmptyMethods inherited from interface org.javimmutable.collections.IMultiset
deleteAll, multisetCollectorMethods inherited from interface org.javimmutable.collections.ISet
find, get, getValueOr, reject, select, setCollectorMethods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, streamMethods 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:IMultisetAdds one occurrence of value to the multiset. -
insert
Description copied from interface:IMultisetAdds count number of occurrences of value to the multiset. Count must be greater than or equal to zero. -
contains
Description copied from interface:IMultisetDetermines if the multiset contains at least one occurrence of the specified value -
containsAtLeast
Description copied from interface:IMultisetDetermines if the multiset contains at least count occurrences of value.- Specified by:
containsAtLeastin 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:IMultisetDetermines 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:
containsAllin interfaceIMultiset<T>- Specified by:
containsAllin interfaceISet<T>- Parameters:
other- contains values to be checked for- Returns:
- true if this multiset contains all values
-
containsAll
Description copied from interface:IMultisetDetermines 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:
containsAllin interfaceIMultiset<T>- Specified by:
containsAllin interfaceISet<T>- Parameters:
other- contains values to be checked for- Returns:
- true if this multiset contains all values
-
containsAllOccurrences
Description copied from interface:IMultisetDetermines if the multiset contains every occurrence of all the values in other. If other is empty, returns true. Slow operation.- Specified by:
containsAllOccurrencesin interfaceIMultiset<T>- Parameters:
other- contains values to be checked for- Returns:
- true if this multiset contains all occurrences
-
containsAllOccurrences
Description copied from interface:IMultisetDetermines if the multiset contains every occurrence of all the values in other. If other is empty, returns true. Slow operation.- Specified by:
containsAllOccurrencesin interfaceIMultiset<T>- Parameters:
other- contains values to be checked for- Returns:
- true if this multiset contains all occurrences
-
containsAllOccurrences
Description copied from interface:IMultisetDetermines if the multiset contains every occurrence of all the values in other. If other is empty, returns true.- Specified by:
containsAllOccurrencesin interfaceIMultiset<T>- Parameters:
values- contains values to be checked for- Returns:
- true if this multiset contains all occurrences
-
containsAny
Description copied from interface:IMultisetDetermines if the multiset and other have at least one value in common. Returns false if other is empty.- Specified by:
containsAnyin interfaceIMultiset<T>- Specified by:
containsAnyin interfaceISet<T>- Parameters:
other- contains values to be checked for- Returns:
- true if this multiset contains a value
-
containsAny
Description copied from interface:IMultisetDetermines if the multiset and other have at least one value in common. Returns false if other is empty.- Specified by:
containsAnyin interfaceIMultiset<T>- Specified by:
containsAnyin interfaceISet<T>- Parameters:
other- contains values to be checked for- Returns:
- true if this multiset contains a value
-
delete
Description copied from interface:IMultisetRemoves every occurrence of value from the multiset. -
deleteOccurrence
Description copied from interface:IMultisetRemoves one occurrence of value from the multiset.- Specified by:
deleteOccurrencein interfaceIMultiset<T>- Parameters:
value- value to remove- Returns:
- new multiset reflecting the change
-
deleteOccurrence
Description copied from interface:IMultisetRemoves 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:
deleteOccurrencein interfaceIMultiset<T>- Parameters:
value- value to removesubtractBy- number of occurrences to remove- Returns:
- new multiset reflecting the change
-
deleteAll
Description copied from interface:IMultisetRemoves all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other. -
deleteAll
Description copied from interface:IMultisetRemoves all occurrences of each value in other from the multiset. Synonymous to calling delete() on each element of other. -
deleteAllOccurrences
Description copied from interface:IMultisetRemoves each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.- Specified by:
deleteAllOccurrencesin interfaceIMultiset<T>- Parameters:
other- contains occurrences to delete- Returns:
- new multiset reflecting the change
-
deleteAllOccurrences
Description copied from interface:IMultisetRemoves each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.- Specified by:
deleteAllOccurrencesin interfaceIMultiset<T>- Parameters:
other- contains occurrences to delete- Returns:
- new multiset reflecting the change
-
deleteAllOccurrences
Description copied from interface:IMultisetRemoves each occurrence in other from the multiset. Synonymous to calling deleteOccurrence() on each element of other.- Specified by:
deleteAllOccurrencesin interfaceIMultiset<T>- Parameters:
other- contains occurrences to delete- Returns:
- new multiset reflecting the change
-
insertAll
Description copied from interface:IMultisetAdds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
insertAll
Description copied from interface:IMultisetAdds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
insertAll
Description copied from interface:IMultisetAdds each occurrence in values to the multiset. Synonymous to calling insert on each element of values. -
union
Description copied from interface:IMultisetCombines 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:IMultisetCombines 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:IMultisetCombines 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:IMultisetCreates 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:
intersectionin interfaceIMultiset<T>- Specified by:
intersectionin interfaceISet<T>- Parameters:
other- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultisetCreates 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:
intersectionin interfaceIMultiset<T>- Specified by:
intersectionin interfaceISet<T>- Parameters:
other- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultisetCreates 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:
intersectionin interfaceIMultiset<T>- Parameters:
other- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultisetCreates 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:
intersectionin interfaceIMultiset<T>- Specified by:
intersectionin interfaceISet<T>- Parameters:
other- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
intersection
Description copied from interface:IMultisetCreates 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:
intersectionin interfaceIMultiset<T>- Specified by:
intersectionin interfaceISet<T>- Parameters:
other- contains values to intersect with this multiset- Returns:
- new multiset reflecting the change
-
count
Description copied from interface:IMultisetReturns 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:IMultisetManually 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:
isEmptyin interfaceICollection<T>- Returns:
- true only if collection contains no values
-
size
public int size() -
occurrenceCount
public int occurrenceCount()- Specified by:
occurrenceCountin 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:IStreamableOverridden 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:
iteratorin interfaceIStreamable<T>- Specified by:
iteratorin interfaceIterable<T>- Specified by:
iteratorin interfaceSplitableIterable<T>
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristicsin interfaceIStreamable<T>- Returns:
- characteristics value used when creating Spliterators
-
entries
Description copied from interface:IMultisetStream iterates through each Entry, that contains a unique value and the count of occurrences. -
occurrences
Description copied from interface:IMultisetIStreamable that iterates through each occurrence in the multiset the correct number of times.- Specified by:
occurrencesin 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:InvariantCheckableChecks invariants of implementing class.- Specified by:
checkInvariantsin interfaceInvariantCheckable
-