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 intadd(T entry)Add an entry with multiplicity 1.intadd(T entry, int mult)Add one entry with given multiplicity.voidaddAll(Multiset<T> other)Add another multiset to this.voidaddAll(java.util.Collection<T> values)Add all values of the given collection.voidaddAll(T[] values)Add all values of the given array.java.util.Set<java.util.Map.Entry<T,java.lang.Integer>>entrySet()booleanequals(java.lang.Object o)java.lang.Integerget(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.Integerremove(java.lang.Object key)Removes one instance of the given value from this multiset, if at least one element is contained.intremove(T key, int mult)Remove the given key multiple times.intremoveAll(T key)Removes the key-value pair of the given key no matter what its multiplicity wasintsize()java.util.List<T>toList()java.lang.StringtoString()inttotalCount()
-
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:
toStringin classjava.lang.Object
-
equals
boolean equals(java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-