Package com.github.tommyettinger.ds
Class EnumFloatOrderedMap
java.lang.Object
com.github.tommyettinger.ds.EnumFloatMap
com.github.tommyettinger.ds.EnumFloatOrderedMap
- All Implemented Interfaces:
Arrangeable,Ordered<Enum<?>>,Iterable<EnumFloatMap.Entry>
An insertion-ordered map where the keys are
This class never actually hashes keys in its primary operations (get(), put(), remove(), containsKey(), etc.), since it can rely on keys having an Enum type, and so having
The key universe is an important concept here; it is simply an array of all possible Enum values the EnumFloatOrderedMap can use as keys, in the specific order they are declared. You almost always get a key universe by calling
This class tries to be as compatible as possible with
Enums and values are primitive floats. Null keys are not allowed.
Unlike EnumMap, this does not require a Class at construction time, which can be useful for serialization
purposes. No allocation is done unless this is changing its table size and/or key universe.
This class never actually hashes keys in its primary operations (get(), put(), remove(), containsKey(), etc.), since it can rely on keys having an Enum type, and so having
Enum.ordinal() available. The ordinal allows constant-time access
to a guaranteed-unique int that will always be non-negative and less than the size of the key universe. The table of
possible values always starts sized to fit exactly as many values as there are keys in the key universe.
The key universe is an important concept here; it is simply an array of all possible Enum values the EnumFloatOrderedMap can use as keys, in the specific order they are declared. You almost always get a key universe by calling
MyEnum.values(), but you
can also use Class.getEnumConstants() for an Enum class. You can and generally should reuse key universes in order to
avoid allocations and/or save memory; the constructor EnumFloatOrderedMap(Enum[]) (with no values given) creates an empty EnumFloatOrderedMap with
a given key universe. If you need to use the zero-argument constructor, you can, and the key universe will be obtained from the
first key placed into the EnumFloatOrderedMap. You can also set the key universe with clearToUniverse(Enum[]), in the process of
clearing the map.
This class tries to be as compatible as possible with
EnumMap while using primitive keys,
though this expands on that where possible.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classNested classes/interfaces inherited from class com.github.tommyettinger.ds.EnumFloatMap
EnumFloatMap.Entries, EnumFloatMap.Entry, EnumFloatMap.EntryIterator, EnumFloatMap.KeyIterator, EnumFloatMap.Keys, EnumFloatMap.MapIterator, EnumFloatMap.ValueIterator, EnumFloatMap.ValuesNested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T>Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.Ordered
Ordered.OfBoolean, Ordered.OfByte, Ordered.OfChar, Ordered.OfDouble, Ordered.OfFloat, Ordered.OfInt, Ordered.OfLong, Ordered.OfShort -
Field Summary
FieldsFields inherited from class com.github.tommyettinger.ds.EnumFloatMap
defaultValue, entries1, entries2, keys, keys1, keys2, values1, values2, valueTable -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor; using this will postpone creating the key universe and allocating the value table untilput(java.lang.Enum<?>, float)is first called (potentially indirectly).Creates a new map identical to the specified EnumFloatOrderedMap.EnumFloatOrderedMap(EnumFloatOrderedMap other, int offset, int count) Creates a new map by copyingcountitems from the given EnumFloatOrderedMap, starting atoffsetin that Map, into this.EnumFloatOrderedMap(EnumFloatOrderedMap other, int offset, int count, OrderType type) Creates a new map by copyingcountitems from the given EnumFloatOrderedMap, starting atoffsetin that Map, into this.EnumFloatOrderedMap(EnumFloatOrderedMap map, OrderType type) Creates a new map identical to the specified EnumFloatOrderedMap.EnumFloatOrderedMap(OrderType type) Constructor that only specifies an OrderType; using this will postpone creating the key universe and allocating the value table untilput(java.lang.Enum<?>, float)is first called (potentially indirectly).EnumFloatOrderedMap(Class<? extends Enum<?>> universeClass) Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined by the ClassuniverseClass, assuming universeClass is non-null.EnumFloatOrderedMap(Class<? extends Enum<?>> universeClass, OrderType type) Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined by the ClassuniverseClass, assuming universeClass is non-null.EnumFloatOrderedMap(Enum<?>[] universe) Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined inuniverse, assuming universe stores every possible constant in one Enum type.EnumFloatOrderedMap(Enum<?>[] keys, float[] values) Given two side-by-side arrays, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it.EnumFloatOrderedMap(Enum<?>[] keys, float[] values, OrderType type) Given two side-by-side arrays, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it.EnumFloatOrderedMap(Enum<?>[] universe, OrderType type) Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined inuniverse, assuming universe stores every possible constant in one Enum type.EnumFloatOrderedMap(Collection<? extends Enum<?>> keys, PrimitiveCollection.OfFloat values) Given two side-by-side collections, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it.EnumFloatOrderedMap(Collection<? extends Enum<?>> keys, PrimitiveCollection.OfFloat values, OrderType type) Given two side-by-side collections, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChanges the keybeforetoafterwithout changing its position in the order or its value.booleanChanges the key at the givenindexin the order toafter, without changing the ordering of other entries or any values.appendTo(StringBuilder sb, String entrySeparator, String keyValueSeparator, boolean braces, Appender<Enum<?>> keyAppender, FloatAppender valueAppender) Appends to a StringBuilder from the contents of this EnumFloatOrderedMap, but uses the givenAppenderandFloatAppenderto convert each key and each value to a customizable representation and append them to a StringBuilder.voidclear()Removes all the elements from this map.voidclearToUniverse(Class<? extends Enum<?>> universe) Removes all the elements from this map and can reset the universe of possible Enum items this can hold.voidclearToUniverse(Enum<?>[] universe) Removes all the elements from this map and can reset the universe of possible Enum items this can hold.entrySet()Returns a Set of Map.Entry, containing the entries in the map.floatgetAndIncrement(Enum<?> key, float defaultValue, float increment) Returns the key's current value and increments the stored value.floatgetAt(int index) Gets the float value at the givenindexin the insertion order.iterator()Reuses the iterator of the reusedEnumFloatMap.Entriesproduced byentrySet(); does not permit nested iteration.Enum<?>keyAt(int index) Gets the K key at the givenindexin the insertion order.keySet()Returns aSetview of the keys contained in this map.static EnumFloatOrderedMapof()Constructs an empty map.static EnumFloatOrderedMapConstructs a map given alternating keys and values.ObjectList<Enum<?>>order()Gets the ObjectList of keys in the order this class will iterate through them.static EnumFloatOrderedMapparse(String str, String entrySeparator, String keyValueSeparator, PartialParser<Enum<?>> keyParser) Creates a new map by parsing all ofstrwith the given PartialParser for keys, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".static EnumFloatOrderedMapparse(String str, String entrySeparator, String keyValueSeparator, PartialParser<Enum<?>> keyParser, boolean brackets) Creates a new map by parsing all ofstr(or ifbracketsis true, all but the first and last chars) with the given PartialParser for keys, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".static EnumFloatOrderedMapparse(String str, String entrySeparator, String keyValueSeparator, PartialParser<Enum<?>> keyParser, int offset, int length) Creates a new map by parsing the given subrange ofstrwith the given PartialParser for keys, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".floatReturns the old value associated with the specified key, or this map'sEnumFloatMap.defaultValueif there was no prior value.floatPuts the given key and value into this map at the given index in its order.voidputAll(int insertionIndex, EnumFloatOrderedMap other, int offset, int count) Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting starting atinsertionIndexin the iteration order.voidPuts every key-value pair in the given map into this, with the values from the given map overwriting the previous values if two keys are identical.voidputAll(EnumFloatOrderedMap other, int offset, int count) Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting at the end of the iteration order.voidputAll(ObjectFloatOrderedMap<Enum<?>> map) Copies all the mappings from the specified map to this map (optional operation).voidputAll(Collection<? extends Enum<?>> keys, PrimitiveCollection.OfFloat values) Given two side-by-side collections, one of Enum keys, one of float values, this inserts each pair of key and value into this map with put().floatputOrDefault(Enum<?> key, float value, float defaultValue) Acts likeEnumFloatMap.put(Enum, float), but uses the specifieddefaultValueinstead ofthe default value for this EnumFloatMap.floatfloatremoveAt(int index) Removes the entry at the given index in the order, returning the value of that entry.voidremoveRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive.floatsetAt(int index, float v) Changes the value at a specifiedindexin the iteration order tov, without changing keys at all.voidsort()Sorts this EnumFloatOrderedMap in-place by the keys' natural ordering.voidsort(Comparator<? super Enum<?>> comp) Sorts this EnumFloatOrderedMap in-place by the given Comparator used on the keys.voidsortByValue(FloatComparator comp) Sorts this EnumFloatOrderedMap in-place by the given FloatComparator used on the values.voidtruncate(int newSize) Reduces the size of the map to the specified size.values()Returns a PrimitiveCollection for the values in the map.static EnumFloatOrderedMapwith()Constructs an empty map.static EnumFloatOrderedMapConstructs a single-entry map given one key and one value.static EnumFloatOrderedMapConstructs a map given alternating keys and values.static EnumFloatOrderedMapConstructs a map given alternating keys and values.static EnumFloatOrderedMapwith(Enum<?> key0, Number value0, Enum<?> key1, Number value1, Enum<?> key2, Number value2, Enum<?> key3, Number value3) Constructs a map given alternating keys and values.static EnumFloatOrderedMapConstructs a map given alternating keys and values.static EnumFloatOrderedMapConstructs an empty map.static EnumFloatOrderedMapwithPrimitive(Enum<?> key0, float value0) Constructs a single-entry map given one key and one value.static EnumFloatOrderedMapwithPrimitive(Enum<?> key0, float value0, Enum<?> key1, float value1) Constructs a map given alternating keys and values.static EnumFloatOrderedMapwithPrimitive(Enum<?> key0, float value0, Enum<?> key1, float value1, Enum<?> key2, float value2) Constructs a map given alternating keys and values.static EnumFloatOrderedMapwithPrimitive(Enum<?> key0, float value0, Enum<?> key1, float value1, Enum<?> key2, float value2, Enum<?> key3, float value3) Constructs a map given alternating keys and values.Methods inherited from class com.github.tommyettinger.ds.EnumFloatMap
appendTo, combine, combine, computeIfAbsent, containsKey, containsValue, equals, findKey, get, getDefaultValue, getOrDefault, getUniverse, hashCode, isEmpty, notEmpty, putAll, putAll, putAll, putAll, putAll, putLegible, putLegible, putLegible, putLegible, putPairs, remove, replace, setDefaultValue, size, toString, toString, toString, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.github.tommyettinger.ds.Arrangeable
rearrange, shuffle, sizeMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface com.github.tommyettinger.ds.Ordered
getOrderType, random, random, reverse, selectRanked, selectRankedIndex, shuffle, swap
-
Field Details
-
ordering
-
-
Constructor Details
-
EnumFloatOrderedMap
Constructor that only specifies an OrderType; using this will postpone creating the key universe and allocating the value table untilput(java.lang.Enum<?>, float)is first called (potentially indirectly). You can also useclearToUniverse(java.lang.Enum<?>[])to set the key universe and value table.- Parameters:
type- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumFloatOrderedMap
Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined inuniverse, assuming universe stores every possible constant in one Enum type. This map will start empty. You almost always obtain universe from callingvalues()on an Enum type, and you can share one reference to one Enum array across many EnumFloatOrderedMap instances if you don't modify the shared array. Sharing the same universe helps save some memory if you have (very) many EnumFloatOrderedMap instances.- Parameters:
universe- almost always, the result of callingvalues()on an Enum type; used directly, not copiedtype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumFloatOrderedMap
Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined by the ClassuniverseClass, assuming universeClass is non-null. This simply callsEnumFloatOrderedMap(Enum[])for convenience. Note that this constructor allocates a new array of Enum constants each time it is called, where if you useEnumFloatOrderedMap(Enum[]), you can reuse an unmodified array to reduce allocations.- Parameters:
universeClass- the Class of an Enum type that defines the universe of valid Enum items this can holdtype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumFloatOrderedMap
Creates a new map identical to the specified EnumFloatOrderedMap. This will share a key universe with the given EnumFloatOrderedMap, if non-null. This overload allows specifying the OrderType independently of the one used inmap.- Parameters:
map- an EnumFloatOrderedMap to copytype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumFloatOrderedMap
Given two side-by-side arrays, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller array.- Parameters:
keys- an array of Enum keysvalues- an array of float valuestype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumFloatOrderedMap
public EnumFloatOrderedMap(Collection<? extends Enum<?>> keys, PrimitiveCollection.OfFloat values, OrderType type) Given two side-by-side collections, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller collection.- Parameters:
keys- a Collection of Enum keysvalues- a PrimitiveCollection of float valuestype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumFloatOrderedMap
Creates a new map by copyingcountitems from the given EnumFloatOrderedMap, starting atoffsetin that Map, into this. This overload allows specifying the OrderType independently of the one used inother.- Parameters:
other- another EnumFloatOrderedMapoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from othertype- eitherOrderType.BAGto use unreliable ordering with faster deletion, or anything else to use a list type that takes longer to delete but maintains insertion order reliably
-
EnumFloatOrderedMap
public EnumFloatOrderedMap()Empty constructor; using this will postpone creating the key universe and allocating the value table untilput(java.lang.Enum<?>, float)is first called (potentially indirectly). You can also useclearToUniverse(java.lang.Enum<?>[])to set the key universe and value table. -
EnumFloatOrderedMap
Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined inuniverse, assuming universe stores every possible constant in one Enum type. This map will start empty. You almost always obtain universe from callingvalues()on an Enum type, and you can share one reference to one Enum array across many EnumFloatOrderedMap instances if you don't modify the shared array. Sharing the same universe helps save some memory if you have (very) many EnumFloatOrderedMap instances.- Parameters:
universe- almost always, the result of callingvalues()on an Enum type; used directly, not copied
-
EnumFloatOrderedMap
Initializes this map so that it has exactly enough capacity as needed to contain each Enum constant defined by the ClassuniverseClass, assuming universeClass is non-null. This simply callsEnumFloatOrderedMap(Enum[])for convenience. Note that this constructor allocates a new array of Enum constants each time it is called, where if you useEnumFloatOrderedMap(Enum[]), you can reuse an unmodified array to reduce allocations.- Parameters:
universeClass- the Class of an Enum type that defines the universe of valid Enum items this can hold
-
EnumFloatOrderedMap
Creates a new map identical to the specified EnumFloatOrderedMap. This will share a key universe with the given EnumFloatOrderedMap, if non-null. This overload uses the OrderType of the given map.- Parameters:
map- an EnumFloatOrderedMap to copy
-
EnumFloatOrderedMap
Given two side-by-side arrays, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller array.- Parameters:
keys- an array of Enum keysvalues- an array of float values
-
EnumFloatOrderedMap
Given two side-by-side collections, one of Enum keys, one of float values, this constructs a map and inserts each pair of key and value into it. If keys and values have different lengths, this only uses the length of the smaller collection.- Parameters:
keys- a Collection of Enum keysvalues- a PrimitiveCollection of float values
-
EnumFloatOrderedMap
Creates a new map by copyingcountitems from the given EnumFloatOrderedMap, starting atoffsetin that Map, into this. This overload uses the OrderType of the given map.- Parameters:
other- another EnumFloatOrderedMapoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from other
-
-
Method Details
-
putAll
Given two side-by-side collections, one of Enum keys, one of float values, this inserts each pair of key and value into this map with put().- Overrides:
putAllin classEnumFloatMap- Parameters:
keys- a Collection of Enum keysvalues- a PrimitiveCollection of float values
-
put
Returns the old value associated with the specified key, or this map'sEnumFloatMap.defaultValueif there was no prior value. If this EnumFloatOrderedMap does not yet have a key universe and/or value table, this gets the key universe fromkeyand uses it from now on for this EnumFloatOrderedMap.- Overrides:
putin classEnumFloatMap- Parameters:
key- the Enum key to try to place into this EnumFloatOrderedMapvalue- the float value to associate withkey- Returns:
- the previous value associated with
key, orEnumFloatMap.getDefaultValue()if the given key was not present
-
put
Puts the given key and value into this map at the given index in its order. If the key is already present at a different index, it is moved to the given index and its value is set to the given value.- Parameters:
key- an Enum key; must not be nullvalue- a float valueindex- the index in the order to place the given key and value; must be non-negative and less thanEnumFloatMap.size()- Returns:
- the previous value associated with key, if there was one, or
EnumFloatMap.defaultValueotherwise
-
putOrDefault
Description copied from class:EnumFloatMapActs likeEnumFloatMap.put(Enum, float), but uses the specifieddefaultValueinstead ofthe default value for this EnumFloatMap.- Overrides:
putOrDefaultin classEnumFloatMap- Parameters:
key- the Enum key to try to place into this EnumFloatMapvalue- the float value to associate withkeydefaultValue- the float value to return ifkeywas not already present- Returns:
- the previous value associated with
key, or the givendefaultValueif the given key was not present
-
putAll
Puts every key-value pair in the given map into this, with the values from the given map overwriting the previous values if two keys are identical. This will put keys in the order of the given map.- Parameters:
map- a map with compatible key and value types; will not be modified
-
putAll
Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting at the end of the iteration order.- Parameters:
other- a non-null ordered map with the same type and compatible generic typesoffset- the first index inotherto usecount- how many indices inotherto use
-
putAll
Adds up tocountentries, starting fromoffset, in the mapotherto this set, inserting starting atinsertionIndexin the iteration order.- Parameters:
insertionIndex- where to insert into the iteration orderother- a non-null ordered map with the same type and compatible generic typesoffset- the first index inotherto usecount- how many indices inotherto use
-
remove
- Overrides:
removein classEnumFloatMap
-
removeAt
public float removeAt(int index) Removes the entry at the given index in the order, returning the value of that entry.- Parameters:
index- the index of the entry to remove; must be at least 0 and less thanEnumFloatMap.size()- Returns:
- the value of the removed entry
-
removeRange
public void removeRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive. Note that this takes different arguments than some other range-related methods; this needs a start index and an end index, rather than a count of items. This matches the behavior in the JDK collections.- Specified by:
removeRangein interfaceOrdered<Enum<?>>- Parameters:
start- the first index to remove, inclusiveend- the last index (after what should be removed), exclusive
-
truncate
public void truncate(int newSize) Reduces the size of the map to the specified size. If the map is already smaller than the specified size, no action is taken.- Parameters:
newSize- the target size to try to reach by removing items, if smaller than the current size
-
putAll
Copies all the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of callingput(k, v)on this map once for each mapping from keykto valuevin the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.
Note thatputAll(EnumFloatOrderedMap)is more specific and can be more efficient by using the internal details of this class.- Parameters:
map- mappings to be stored in this map- Throws:
UnsupportedOperationException- if theputAlloperation is not supported by this mapClassCastException- if the class of a key or value in the specified map prevents it from being stored in this mapNullPointerException- if the specified map is null, or if this map does not permit null keys or values, and the specified map contains null keys or valuesIllegalArgumentException- if some property of a key or value in the specified map prevents it from being stored in this map
-
getAndIncrement
Description copied from class:EnumFloatMapReturns the key's current value and increments the stored value. If the key is not in the map, defaultValue + increment is put into the map and defaultValue is returned.- Overrides:
getAndIncrementin classEnumFloatMap
-
alter
Changes the keybeforetoafterwithout changing its position in the order or its value. Returns true ifafterhas been added to the EnumFloatOrderedMap andbeforehas been removed; returns false ifafteris already present orbeforeis not present. If you are iterating over an EnumFloatOrderedMap and have an index, you should preferalterAt(int, Enum), which doesn't need to search for an index like this does and so can be faster.- Parameters:
before- a key that must be present for this to succeedafter- a key that must not be in this map for this to succeed- Returns:
- true if
beforewas removed andafterwas added, false otherwise
-
alterAt
Changes the key at the givenindexin the order toafter, without changing the ordering of other entries or any values. Ifafteris already present, this returns false; it will also return false ifindexis invalid for the size of this map. Otherwise, it returns true. Unlikealter(Enum, Enum), this operates in constant time.- Parameters:
index- the index in the order of the key to change; must be non-negative and less thanEnumFloatMap.size()after- the key that will replace the contents atindex; this key must not be present for this to succeed- Returns:
- true if
aftersuccessfully replaced the key atindex, false otherwise
-
setAt
public float setAt(int index, float v) Changes the value at a specifiedindexin the iteration order tov, without changing keys at all. Ifindexisn't currently a valid index in the iteration order, this returns null. Otherwise, it returns the value that was previously held atindex, which may also be null.- Parameters:
v- the new float value to assignindex- the index in the iteration order to setvat- Returns:
- the previous value held at
indexin the iteration order, which may be null if the value was null or ifindexwas invalid
-
getAt
public float getAt(int index) Gets the float value at the givenindexin the insertion order. The index should be between 0 (inclusive) andEnumFloatMap.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andEnumFloatMap.size()(exclusive)- Returns:
- the value at the given index
-
keyAt
Gets the K key at the givenindexin the insertion order. The index should be between 0 (inclusive) andEnumFloatMap.size()(exclusive).- Parameters:
index- an index in the insertion order, between 0 (inclusive) andEnumFloatMap.size()(exclusive)- Returns:
- the key at the given index
-
clear
public void clear()Description copied from class:EnumFloatMapRemoves all the elements from this map. The map will be empty after this call returns. This does not change the universe of possible Enum items this can hold.- Overrides:
clearin classEnumFloatMap
-
clearToUniverse
Description copied from class:EnumFloatMapRemoves all the elements from this map and can reset the universe of possible Enum items this can hold. The map will be empty after this call returns. This changes the universe of possible Enum items this can hold to matchuniverse. Ifuniverseis null, this resets this map to the state it would have afterEnumFloatMap()was called. If the table this would need is the same size as or smaller than the current table (such as ifuniverseis the same as the universe here), this will not allocate, but will still clear any items this holds and will set the universe to the given one. Otherwise, this allocates and uses a new table of a larger size, with nothing in it, and uses the given universe. This always usesuniversedirectly, without copying.
This can be useful to allow an EnumFloatMap that was created withEnumFloatMap()to share a universe with other EnumFloatMaps.- Overrides:
clearToUniversein classEnumFloatMap- Parameters:
universe- the universe of possible Enum items this can hold; almost always produced byvalues()on an Enum
-
clearToUniverse
Description copied from class:EnumFloatMapRemoves all the elements from this map and can reset the universe of possible Enum items this can hold. The map will be empty after this call returns. This changes the universe of possible Enum items this can hold to match the Enum constants inuniverse. Ifuniverseis null, this resets this map to the state it would have afterEnumFloatMap()was called. If the table this would need is the same size as or smaller than the current table (such as ifuniverseis the same as the universe here), this will not allocate, but will still clear any items this holds and will set the universe to the given one. Otherwise, this allocates and uses a new table of a larger size, with nothing in it, and uses the given universe. This callsClass.getEnumConstants()if universe is non-null, which allocates a new array.
You may want to prefer callingEnumFloatMap.clearToUniverse(Enum[])(the overload that takes an array), because it can be used to share one universe array between many EnumFloatMap instances. This overload, given a Class, has to callClass.getEnumConstants()and thus allocate a new array each time this is called.- Overrides:
clearToUniversein classEnumFloatMap- Parameters:
universe- the Class of an Enum type that stores the universe of possible Enum items this can hold
-
order
Gets the ObjectList of keys in the order this class will iterate through them. Returns a direct reference to the same ObjectList this uses, so changes to the returned list will also change the iteration order here. -
sort
public void sort()Sorts this EnumFloatOrderedMap in-place by the keys' natural ordering. -
sort
Sorts this EnumFloatOrderedMap in-place by the given Comparator used on the keys. Ifcompis null, then this will sort by the natural ordering of the keys. -
sortByValue
Sorts this EnumFloatOrderedMap in-place by the given FloatComparator used on the values.compmust not be null, and must be able to comparefloatvalues. You can useFloatComparators.NATURAL_COMPARATORto do whatsort()does (just sorting values in this case instead of keys); there is also a reversed comparator available,FloatComparators.OPPOSITE_COMPARATOR.- Parameters:
comp- a non-nullFloatComparator
-
keySet
Returns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremoveoperation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearoperations. It does not support theaddoraddAlloperations.Note that the same Collection instance is returned each time this method is called. Use the
OrderedMapKeys(EnumFloatOrderedMap)constructor for nested or multithreaded iteration.- Overrides:
keySetin classEnumFloatMap- Returns:
- a set view of the keys contained in this map
-
values
Returns a PrimitiveCollection for the values in the map. Remove is supported by the PrimitiveCollection's iterator.Note that the same PrimitiveCollection.OfFloat instance is returned each time this method is called. Use the
OrderedMapValues(EnumFloatOrderedMap)constructor for nested or multithreaded iteration.- Overrides:
valuesin classEnumFloatMap- Returns:
- a
PrimitiveCollection.OfFloatof the float values
-
entrySet
Returns a Set of Map.Entry, containing the entries in the map. Remove is supported by the Set's iterator.Note that the same iterator instance is returned each time this method is called. Use the
OrderedMapEntries(EnumFloatOrderedMap)constructor for nested or multithreaded iteration.- Overrides:
entrySetin classEnumFloatMap- Returns:
- a
SetofMap.Entrykey-value pairs
-
iterator
Reuses the iterator of the reusedEnumFloatMap.Entriesproduced byentrySet(); does not permit nested iteration. Iterate overOrderedMapEntries(EnumFloatOrderedMap)if you need nested or multithreaded iteration. You can remove an Entry from this EnumFloatOrderedMap using this Iterator.- Specified by:
iteratorin interfaceIterable<EnumFloatMap.Entry>- Overrides:
iteratorin classEnumFloatMap- Returns:
- an
Iteratorover key-value pairs asEnumFloatMap.Entryvalues
-
appendTo
public StringBuilder appendTo(StringBuilder sb, String entrySeparator, String keyValueSeparator, boolean braces, Appender<Enum<?>> keyAppender, FloatAppender valueAppender) Appends to a StringBuilder from the contents of this EnumFloatOrderedMap, but uses the givenAppenderandFloatAppenderto convert each key and each value to a customizable representation and append them to a StringBuilder. These functions are often method references to methods in Base, such asBase.appendUnsigned(CharSequence, float). To use the default toString representation, you can useAppender::appendas an appender, or to use the readable EnumEnum.name(), useAppender.ENUM_NAME_APPENDER. UseFloatAppender.DEFAULTorFloatAppender.READABLEfor human-readable or source-code-readable results, respectively.- Overrides:
appendToin classEnumFloatMap- Parameters:
sb- a StringBuilder that this can append toentrySeparator- how to separate entries, such as", "keyValueSeparator- how to separate each key from its value, such as"="or":"braces- true to wrap the output in curly braces, or false to omit themkeyAppender- a function that takes a StringBuilder and a K, and returns the modified StringBuildervalueAppender- a function that takes a StringBuilder and a float, and returns the modified StringBuilder- Returns:
sb, with the appended keys and values of this map
-
with
Constructs an empty map. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Returns:
- a new map containing nothing
-
with
Constructs a single-entry map given one key and one value. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number value to a primitive float, regardless of which Number type was used.- Parameters:
key0- the first and only Enum keyvalue0- the first and only value; will be converted to primitive float- Returns:
- a new map containing just the entry mapping key0 to value0
-
with
Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number values to primitive floats, regardless of which Number type was used.- Parameters:
key0- an Enum keyvalue0- a Number for a value; will be converted to primitive floatkey1- an Enum keyvalue1- a Number for a value; will be converted to primitive float- Returns:
- a new map containing the given key-value pairs
-
with
public static EnumFloatOrderedMap with(Enum<?> key0, Number value0, Enum<?> key1, Number value1, Enum<?> key2, Number value2) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number values to primitive floats, regardless of which Number type was used.- Parameters:
key0- an Enum keyvalue0- a Number for a value; will be converted to primitive floatkey1- an Enum keyvalue1- a Number for a value; will be converted to primitive floatkey2- an Enum keyvalue2- a Number for a value; will be converted to primitive float- Returns:
- a new map containing the given key-value pairs
-
with
public static EnumFloatOrderedMap with(Enum<?> key0, Number value0, Enum<?> key1, Number value1, Enum<?> key2, Number value2, Enum<?> key3, Number value3) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Like the more-argument with(), this will convert its Number values to primitive floats, regardless of which Number type was used.- Parameters:
key0- an Enum keyvalue0- a Number for a value; will be converted to primitive floatkey1- an Enum keyvalue1- a Number for a value; will be converted to primitive floatkey2- an Enum keyvalue2- a Number for a value; will be converted to primitive floatkey3- an Enum keyvalue3- a Number for a value; will be converted to primitive float- Returns:
- a new map containing the given key-value pairs
-
with
Constructs a map given alternating keys and values. This can be useful in some code-generation scenarios, or when you want to make a map conveniently by-hand and have it populated at the start. You can also useEnumFloatOrderedMap(Enum[], float[]), which takes all keys and then all values. This needs all keys to be Enum constants. All values must be some type of boxed Number, such asIntegerorDouble, and will be converted to primitivefloats. Any keys that don't have Enum as their type or values that aren'tNumbers have that entry skipped.- Parameters:
key0- the first Enum keyvalue0- the first value; will be converted to primitive floatrest- an array or varargs of alternating Enum, Number, Enum, Number... elements- Returns:
- a new map containing the given keys and values
-
parse
public static EnumFloatOrderedMap parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<Enum<?>> keyParser) Creates a new map by parsing all ofstrwith the given PartialParser for keys, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".
ThekeyParseris often produced byPartialParser.enumParser(ObjToObjFunction).- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valuekeyParser- a PartialParser that returns anEnumkey from a section ofstr
-
parse
public static EnumFloatOrderedMap parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<Enum<?>> keyParser, boolean brackets) Creates a new map by parsing all ofstr(or ifbracketsis true, all but the first and last chars) with the given PartialParser for keys, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".
ThekeyParseris often produced byPartialParser.enumParser(ObjToObjFunction).- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valuekeyParser- a PartialParser that returns anEnumkey from a section ofstrbrackets- if true, the first and last chars instrwill be ignored
-
parse
public static EnumFloatOrderedMap parse(String str, String entrySeparator, String keyValueSeparator, PartialParser<Enum<?>> keyParser, int offset, int length) Creates a new map by parsing the given subrange ofstrwith the given PartialParser for keys, with entries separated byentrySeparator, such as", "and the keys separated from values bykeyValueSeparator, such as"=".
ThekeyParseris often produced byPartialParser.enumParser(ObjToObjFunction).- Parameters:
str- a String containing parseable textentrySeparator- the String separating every key-value pairkeyValueSeparator- the String separating every key from its corresponding valuekeyParser- a PartialParser that returns anEnumkey from a section ofstroffset- the first position to read parseable text from instrlength- how many chars to read; -1 is treated as maximum length
-
withPrimitive
Constructs an empty map. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Returns:
- a new map containing nothing
-
withPrimitive
Constructs a single-entry map given one key and one value. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- an Enum for a keyvalue0- a float for a value- Returns:
- a new map containing just the entry mapping key0 to value0
-
withPrimitive
public static EnumFloatOrderedMap withPrimitive(Enum<?> key0, float value0, Enum<?> key1, float value1) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- an Enum keyvalue0- a float for a valuekey1- an Enum keyvalue1- a float for a value- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
public static EnumFloatOrderedMap withPrimitive(Enum<?> key0, float value0, Enum<?> key1, float value1, Enum<?> key2, float value2) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- an Enum keyvalue0- a float for a valuekey1- an Enum keyvalue1- a float for a valuekey2- an Enum keyvalue2- a float for a value- Returns:
- a new map containing the given key-value pairs
-
withPrimitive
public static EnumFloatOrderedMap withPrimitive(Enum<?> key0, float value0, Enum<?> key1, float value1, Enum<?> key2, float value2, Enum<?> key3, float value3) Constructs a map given alternating keys and values. This is mostly useful as an optimization forwith(Enum, Number, Object...)when there's no "rest" of the keys or values. Unlike with(), this takes unboxed float as its value type, and will not box it.- Parameters:
key0- an Enum keyvalue0- a float for a valuekey1- an Enum keyvalue1- a float for a valuekey2- an Enum keyvalue2- a float for a valuekey3- an Enum keyvalue3- a float for a value- Returns:
- a new map containing the given key-value pairs
-
of
Constructs an empty map. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have. This is an alias forwith().- Returns:
- a new map containing nothing
-
of
Constructs a map given alternating keys and values. This can be useful in some code-generation scenarios, or when you want to make a map conveniently by-hand and have it populated at the start. You can also useEnumFloatOrderedMap(Enum[], float[]), which takes all keys and then all values. This needs all keys to be Enum constants. All values must be some type of boxed Number, such asIntegerorDouble, and will be converted to primitivefloats. Any keys that don't have Enum as their type or values that aren'tNumbers have that entry skipped. This is an alias forwith(Enum, Number, Object...).- Parameters:
key0- the first Enum keyvalue0- the first value; will be converted to primitive floatrest- an array or varargs of alternating Enum, Number, Enum, Number... elements- Returns:
- a new map containing the given keys and values
-