Package de.tilman_neumann.util
Interface Multiset<T>
- All Known Subinterfaces:
SortedMultiset<T>
- All Known Implementing Classes:
IntegerPartition
,MpiPartition
,Multiset_HashMapImpl
,SortedMultiset_BottomUp
,SortedMultiset_TopDown
public interface Multiset<T>
-
Method Summary
Modifier and Type Method Description int
add(T entry)
Add an entry with multiplicity 1.int
add(T entry, int mult)
Add one entry with given multiplicity.void
addAll(Multiset<T> other)
Add another multiset to this.void
addAll(java.util.Collection<T> values)
Add all values of the given collection.void
addAll(T[] values)
Add all values of the given array.java.util.Set<java.util.Map.Entry<T,java.lang.Integer>>
entrySet()
boolean
equals(java.lang.Object o)
java.lang.Integer
get(java.lang.Object value)
Returns the multiplicity of the given value.Multiset<T>
intersect(Multiset<T> other)
Returns the multiset of elements contained in both this and in the other multiset.java.util.Set<T>
keySet()
java.lang.Integer
remove(java.lang.Object key)
Removes one instance of the given value from this multiset, if at least one element is contained.int
remove(T key, int mult)
Remove the given key multiple times.int
removeAll(T key)
Removes the key-value pair of the given key no matter what its multiplicity wasint
size()
java.util.List<T>
toList()
java.lang.String
toString()
int
totalCount()
-
Method Details
-
add
Add an entry with multiplicity 1.- Parameters:
entry
-- Returns:
- the previous multiplicity of the entry
-
add
Add one entry with given multiplicity.- Parameters:
entry
-mult
-- Returns:
- the previous multiplicity of the entry
-
addAll
Add another multiset to this.- Parameters:
other
-
-
addAll
Add all values of the given collection.- Parameters:
values
-
-
addAll
Add all values of the given array.- Parameters:
values
-
-
get
java.lang.Integer get(java.lang.Object value)Returns the multiplicity of the given value. The key is declared as Object and not as T to match exactly the signature of the same method in the Map-interface. Nevertheless, of course the arguments should be of type T.- Parameters:
value
-- Returns:
- multiplicity
-
remove
java.lang.Integer remove(java.lang.Object key)Removes one instance of the given value from this multiset, if at least one element is contained. The key is declared as Object and not as T to match exactly the signature of the same method in the Map-interface. Nevertheless, of course the arguments should be of type T.- Parameters:
key
-- Returns:
- previous multiplicity of the argument
-
remove
Remove the given key multiple times.- Parameters:
key
-mult
-- Returns:
- old multiplicity
-
removeAll
Removes the key-value pair of the given key no matter what its multiplicity was- Parameters:
key
-- Returns:
- previous multiplicity of the argument
-
intersect
Returns the multiset of elements contained in both this and in the other multiset.- Parameters:
other
-- Returns:
- intersection of this and other
-
size
int size()- Returns:
- The number of different elements
-
totalCount
int totalCount()- Returns:
- Total number of elements, i.e. the sum of multiplicities of all different elements
-
keySet
java.util.Set<T> keySet()- Returns:
- set of distinct values
-
entrySet
java.util.Set<java.util.Map.Entry<T,java.lang.Integer>> entrySet()- Returns:
- set of pairs (value, multiplicity)
-
toList
java.util.List<T> toList()- Returns:
- this as a flat list in which each value occurs 'multiplicity' times.
-
toString
java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
equals
boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-