Package squidpony.squidmath
Class EnumOrderedMap<K extends Enum<?>,V>
java.lang.Object
squidpony.squidmath.OrderedMap<K,V>
squidpony.squidmath.EnumOrderedMap<K,V>
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,V>
,SortedMap<K,V>
public class EnumOrderedMap<K extends Enum<?>,V> extends OrderedMap<K,V>
A simple alternative to EnumMap that has a zero-argument constructor (which makes serialization easier) but is a
little less efficient. However, it supports more features by inheriting from
Created by Tommy Ettinger on 10/21/2017.
OrderedMap
, such as retrieval of
random keys or values with OrderedMap.randomKey(IRNG)
and OrderedMap.randomValue(IRNG)
, iteration in insertion order
instead of always using enum declaration order (order can be shuffled with OrderedMap.shuffle(IRNG)
or reordered with
OrderedMap.reorder(int...)
), and a little more. The implementation is nearly trivial due to how OrderedMap allows
customization of hashing strategy with its IHasher option, and this class always uses a specific custom IHasher to
hash Enum values by their ordinal. This IHasher is shared with EnumOrderedSet
.
Created by Tommy Ettinger on 10/21/2017.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class squidpony.squidmath.OrderedMap
OrderedMap.KeyIterator, OrderedMap.KeySet, OrderedMap.MapEntrySet, OrderedMap.ValueCollection, OrderedMap.ValueIterator
-
Field Summary
Fields inherited from class squidpony.squidmath.OrderedMap
containsNullKey, DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR, defRetValue, entries, f, FAST_LOAD_FACTOR, hasher, key, keys, mask, maxFill, n, order, size, value, values, VERY_FAST_LOAD_FACTOR
-
Constructor Summary
Constructors Constructor Description EnumOrderedMap()
EnumOrderedMap(Class<K> enumClass)
EnumOrderedMap(K enumObject)
-
Method Summary
Methods inherited from class squidpony.squidmath.OrderedMap
alter, alterAt, alterAtCarefully, alterCarefully, arraySize, clear, clone, comparator, containsKey, containsValue, defaultReturnValue, defaultReturnValue, ensureCapacity, entryAt, entrySet, equals, firstKey, fixOrder, fixOrder, get, getAndMoveToFirst, getAndMoveToLast, getAt, getMany, getOrDefault, hash64, hashCode, headMap, indexOf, isEmpty, keyAt, keysAsOrderedSet, keySet, lastKey, makeMap, makeMap, maxFill, objectUnwrap, objectUnwrap, positionOf, put, putAll, putAll, putAndMoveToFirst, putAndMoveToLast, putAt, putIfAbsent, putPairs, randomEntry, randomKey, randomValue, rehash, remove, remove, removeAt, removeEntry, removeFirst, removeLast, removeNullEntry, reorder, replace, replace, reverse, shiftKeys, shuffle, size, sort, sort, sortByValue, sortByValue, subMap, swap, swapIndices, tailMap, trim, trim, unwrap, unwrap, values, valuesAsList
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, replaceAll