Package de.tilman_neumann.util
Class SortedMultiset_TopDown<T extends java.lang.Comparable<T>>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.TreeMap<T,java.lang.Integer>
de.tilman_neumann.util.SortedMultiset_TopDown<T>
- Type Parameters:
T
- value class
- All Implemented Interfaces:
Multiset<T>
,SortedMultiset<T>
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<SortedMultiset<T>>
,java.util.Map<T,java.lang.Integer>
,java.util.NavigableMap<T,java.lang.Integer>
,java.util.SortedMap<T,java.lang.Integer>
- Direct Known Subclasses:
MpiPartition
public class SortedMultiset_TopDown<T extends java.lang.Comparable<T>> extends java.util.TreeMap<T,java.lang.Integer> implements SortedMultiset<T>
A sorted set of elements with multiple occurrences, sorted biggest elements first.
Sorting is due to extending TreeMap; with HashMap the sorting behavior
would be undefined. Note that TreeMaps demand that all keys inserted into
the map must implement the Comparable interface!
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,V extends java.lang.Object>
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
-
Constructor Summary
Constructors Constructor Description SortedMultiset_TopDown()
Constructor for an empty multiset, sorted biggest elements first.SortedMultiset_TopDown(Multiset<T> original)
Copy constructor.SortedMultiset_TopDown(java.util.Collection<T> values)
Constructor from an ordinary collection.SortedMultiset_TopDown(T[] values)
Constructor from a value array. -
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.int
compareTo(SortedMultiset<T> other)
Compares this to another ComparableMultiset.boolean
equals(java.lang.Object o)
Sorted multisets are equal if they have exactly the same elements and these elements the same multiplicity.T
getBiggestElement()
T
getSmallestElement()
java.util.Iterator<java.util.Map.Entry<T,java.lang.Integer>>
getTopDownIterator()
int
hashCode()
SortedMultiset<T>
intersect(Multiset<T> other)
Returns the multiset of elements contained in both this and in the other multiset.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 wasjava.util.List<T>
toList()
java.lang.String
toString(java.lang.String entrySep, java.lang.String expSep)
Conversion to String, withint
totalCount()
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, merge, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, putIfAbsent, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
Methods inherited from class java.util.AbstractMap
isEmpty, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, forEach, get, getOrDefault, isEmpty, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, size
Methods inherited from interface de.tilman_neumann.util.Multiset
entrySet, get, keySet, size, toString
Methods inherited from interface java.util.SortedMap
comparator, entrySet, firstKey, keySet, lastKey, values
-
Constructor Details
-
SortedMultiset_TopDown
public SortedMultiset_TopDown()Constructor for an empty multiset, sorted biggest elements first. This sort order is particularly adequate for the parts of additive partitions. -
SortedMultiset_TopDown
Constructor from an ordinary collection. Bigger elements are sorted in before smaller elements.- Parameters:
values
-
-
SortedMultiset_TopDown
Constructor from a value array. Bigger elements are sorted in before smaller elements.- Parameters:
values
-
-
SortedMultiset_TopDown
Copy constructor. Bigger elements are sorted in before smaller elements.- Parameters:
original
-
-
-
Method Details
-
add
Description copied from interface:Multiset
Add an entry with multiplicity 1. -
add
Description copied from interface:Multiset
Add one entry with given multiplicity. -
addAll
Description copied from interface:Multiset
Add another multiset to this. -
addAll
Description copied from interface:Multiset
Add all values of the given collection. -
addAll
Description copied from interface:Multiset
Add all values of the given array. -
remove
public java.lang.Integer remove(java.lang.Object key)Description copied from interface:Multiset
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.- Specified by:
remove
in interfacejava.util.Map<T extends java.lang.Comparable<T>,java.lang.Integer>
- Specified by:
remove
in interfaceMultiset<T extends java.lang.Comparable<T>>
- Overrides:
remove
in classjava.util.TreeMap<T extends java.lang.Comparable<T>,java.lang.Integer>
- Returns:
- previous multiplicity of the argument
-
remove
Description copied from interface:Multiset
Remove the given key multiple times. -
removeAll
Description copied from interface:Multiset
Removes the key-value pair of the given key no matter what its multiplicity was -
intersect
Description copied from interface:SortedMultiset
Returns the multiset of elements contained in both this and in the other multiset. -
totalCount
public int totalCount()- Specified by:
totalCount
in interfaceMultiset<T extends java.lang.Comparable<T>>
- Returns:
- Total number of elements, i.e. the sum of multiplicities of all different elements
-
getSmallestElement
- Specified by:
getSmallestElement
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Returns:
- The smallest element.
-
getBiggestElement
- Specified by:
getBiggestElement
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Returns:
- The biggest element.
-
toList
-
getTopDownIterator
- Specified by:
getTopDownIterator
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Returns:
- an iterator that returns biggest elements first.
-
compareTo
Compares this to another ComparableMultiset. A multiset is bigger than another one if it's biggest element is bigger than the largest element of the other multiset, or the 2.nd-biggest if the biggest elements are equal, or the 3.rd biggest, and so on. -
equals
public boolean equals(java.lang.Object o)Sorted multisets are equal if they have exactly the same elements and these elements the same multiplicity. -
hashCode
public int hashCode() -
toString
public java.lang.String toString(java.lang.String entrySep, java.lang.String expSep)Description copied from interface:SortedMultiset
Conversion to String, with- Specified by:
toString
in interfaceSortedMultiset<T extends java.lang.Comparable<T>>
- Parameters:
entrySep
- e.g. "*" for multiplicative elementsexpSep
- e.g. "^" for multiplicative elements- Returns:
- a string representation of this
-