Package de.tilman_neumann.util
Class SortedMultiset_BottomUp<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_BottomUp<T>
- Type Parameters:
T- element 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:
IntegerPartition
public class SortedMultiset_BottomUp<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 smallest elements first.
Sorting is due to extending TreeMap; with HashMap the sorting behavior would be undefined.
Elements 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_BottomUp()Constructor for an empty multiset, sorted smallest elements first.SortedMultiset_BottomUp(Multiset<T> original)Copy constructor for a multiset, sorted smallest elements first.SortedMultiset_BottomUp(java.util.Collection<T> values)Constructor for a multiset, sorted smallest elements first, from a collection.SortedMultiset_BottomUp(T[] values)Constructor for a multiset, sorted smallest elements first, from a value array. -
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.intcompareTo(SortedMultiset<T> other)Compares this to another SortedMultiset.booleanequals(java.lang.Object o)Sorted multisets are equal if they have exactly the same elements and these elements the same multiplicity.TgetBiggestElement()TgetSmallestElement()java.util.Iterator<java.util.Map.Entry<T,java.lang.Integer>>getTopDownIterator()inthashCode()SortedMultiset<T>intersect(Multiset<T> other)Returns the multiset of elements contained in both this and in the other multiset.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 wasjava.util.List<T>toList()java.lang.StringtoString(java.lang.String entrySep, java.lang.String expSep)Conversion to String, withinttotalCount()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, valuesMethods inherited from class java.util.AbstractMap
isEmpty, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, forEach, get, getOrDefault, isEmpty, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, sizeMethods inherited from interface de.tilman_neumann.util.Multiset
entrySet, get, keySet, size, toStringMethods inherited from interface java.util.SortedMap
comparator, entrySet, firstKey, keySet, lastKey, values
-
Constructor Details
-
SortedMultiset_BottomUp
public SortedMultiset_BottomUp()Constructor for an empty multiset, sorted smallest elements first. This sort order is particularly adequate for the parts of multiplicative partitions (prime factorizations). -
SortedMultiset_BottomUp
Constructor for a multiset, sorted smallest elements first, from a collection.- Parameters:
values-
-
SortedMultiset_BottomUp
Constructor for a multiset, sorted smallest elements first, from a value array.- Parameters:
values-
-
SortedMultiset_BottomUp
Copy constructor for a multiset, sorted smallest elements first.- Parameters:
original-
-
-
Method Details
-
add
Description copied from interface:MultisetAdd an entry with multiplicity 1. -
add
Description copied from interface:MultisetAdd one entry with given multiplicity. -
addAll
Description copied from interface:MultisetAdd another multiset to this. -
addAll
Description copied from interface:MultisetAdd all values of the given collection. -
addAll
Description copied from interface:MultisetAdd all values of the given array. -
remove
public java.lang.Integer remove(java.lang.Object key)Description copied from interface:MultisetRemoves 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:
removein interfacejava.util.Map<T extends java.lang.Comparable<T>,java.lang.Integer>- Specified by:
removein interfaceMultiset<T extends java.lang.Comparable<T>>- Overrides:
removein classjava.util.TreeMap<T extends java.lang.Comparable<T>,java.lang.Integer>- Returns:
- previous multiplicity of the argument
-
remove
Description copied from interface:MultisetRemove the given key multiple times. -
removeAll
Description copied from interface:MultisetRemoves the key-value pair of the given key no matter what its multiplicity was -
intersect
Description copied from interface:SortedMultisetReturns the multiset of elements contained in both this and in the other multiset. -
totalCount
public int totalCount()- Specified by:
totalCountin 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:
getSmallestElementin interfaceSortedMultiset<T extends java.lang.Comparable<T>>- Returns:
- The smallest element.
-
getBiggestElement
- Specified by:
getBiggestElementin interfaceSortedMultiset<T extends java.lang.Comparable<T>>- Returns:
- The biggest element.
-
toList
-
getTopDownIterator
- Specified by:
getTopDownIteratorin interfaceSortedMultiset<T extends java.lang.Comparable<T>>- Returns:
- an iterator that returns biggest elements first.
-
compareTo
Compares this to another SortedMultiset. A sorted 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:SortedMultisetConversion to String, with- Specified by:
toStringin 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
-