Package megamek.common.util.weightedMaps
Class AbstractWeightedMap<K extends Number,T>
java.lang.Object
java.util.AbstractMap<K,T>
java.util.TreeMap<K,T>
megamek.common.util.weightedMaps.AbstractWeightedMap<K,T>
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,,T> NavigableMap<K,,T> SequencedMap<K,,T> SortedMap<K,T>
- Direct Known Subclasses:
WeightedDoubleMap,WeightedIntMap
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
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, putFirst, putIfAbsent, putLast, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.NavigableMap
reversedMethods inherited from interface java.util.SequencedMap
sequencedEntrySet, sequencedKeySet, sequencedValues
-
Constructor Details
-
AbstractWeightedMap
public AbstractWeightedMap()
-
-
Method Details
-
add
- Parameters:
weight- the weight to put the item atvalue- the value of the item- Returns:
- the return value of TreeMap#Put, or null if the value is not added to the map
-
randomItem
- Returns:
- a random item from the weighted map, or null if it is empty
-
randomItem
- Parameters:
key- the key of the item to get (used for simplification and unit testing reasons)- Returns:
- the item from the weighted map, or null if it does not exist
-
randomOptionalItem
- Returns:
- a random item from the weighted map boxed in an Optional, empty if the map is empty
-