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

public abstract class AbstractWeightedMap<K extends Number,T> extends TreeMap<K,T>
See Also:
  • Constructor Details

    • AbstractWeightedMap

      public AbstractWeightedMap()
  • Method Details

    • add

      @Nullable public abstract T add(K weight, T value)
      Parameters:
      weight - the weight to put the item at
      value - the value of the item
      Returns:
      the return value of TreeMap#Put, or null if the value is not added to the map
    • randomItem

      @Nullable public abstract T randomItem()
      Returns:
      a random item from the weighted map, or null if it is empty
    • randomItem

      @Nullable protected T randomItem(K key)
      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

      public Optional<T> randomOptionalItem()
      Returns:
      a random item from the weighted map boxed in an Optional, empty if the map is empty