Class SaturatedEnumToIntMap<K extends Enum<K>>
java.lang.Object
org.klojang.util.collection.SaturatedEnumToIntMap<K>
- Type Parameters:
K- the type of the enum class
- All Implemented Interfaces:
org.klojang.check.extra.Emptyable
public final class SaturatedEnumToIntMap<K extends Enum<K>>
extends Object
implements org.klojang.check.extra.Emptyable
An enum-to-int map. The map is backed by an int array with the same length as the number of constants in
the
enum class. All constructors immediately saturate the map with all enum constants and there is
no way to remove keys from the map. These two preconditions allow SaturatedEnumToIntMap to be
implemented very efficiently.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSaturatedEnumToIntMap(Class<K> enumClass) Creates aSaturatedEnumToIntMap.SaturatedEnumToIntMap(Class<K> enumClass, int initialValue) Creates aSaturatedEnumToIntMap.SaturatedEnumToIntMap(Class<K> enumClass, ToIntFunction<K> initializer) Creates anEnumToIntMapsaturated with all enum constants of the specified enum class.Instantiates a newEnumToIntMapwith the same key-value mappings as the specifiedEnumToIntMap. -
Method Summary
Modifier and TypeMethodDescriptionintAdds the specified value to the value currently associated with the specified key.intcompute(K key, IntUnaryOperator operator) Computes a new value for the value currently associated with the specified keybooleancontainsKey(K key) Always returnstrue(all enum constants will always be present in the map).booleancontainsValue(int val) Returnstrueif this map contains the specified value.entrySet()Returns a Set view of the mappings contained in this map.booleanReturnstrueif the argument is anEnumToIntMapfor the same enum class and if it contains the same key-value mappings.voidforEach(ObjIntConsumer<K> action) Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.intReturns the value to which the specified enum constant is mapped.inthashCode()intIncrements the value currently associated with the specified key.Returns anIntListcontaining the values of this map.booleanisEmpty()Always returnsfalse.keySet()Returns aSetview of the keys contained in this map.keyType()Returns the type of the keys in this map.intMultiplies the value currently associated with the specified key with the specified value.intAssociates the specified value with the specified key in this map.voidAdds all entries of the specified map to this map.voidputAll(SaturatedEnumToIntMap<K> other) Adds all entries of the specified map to this map, overwriting any previous values.Likeput(), but provides a fluent API for adding entries to the map.intsize()Returns the number of key-value mappings in this map.Converts this map to a fully-generic version of this map.toString()values()Returns aCollectionview of the values contained in this map.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.klojang.check.extra.Emptyable
isDeepNotEmpty
-
Constructor Details
-
SaturatedEnumToIntMap
-
SaturatedEnumToIntMap
-
SaturatedEnumToIntMap
Creates anEnumToIntMapsaturated with all enum constants of the specified enum class. The map's values are initialized using the provided function, which takes an enum constant and returns the initial value for the enum constant.- Parameters:
enumClass- the type of the enum classinitializer- a function that initializes the map's values
-
SaturatedEnumToIntMap
Instantiates a newEnumToIntMapwith the same key-value mappings as the specifiedEnumToIntMap.- Parameters:
other- theEnumToIntMapwhose key-value mappings to copy
-
-
Method Details
-
keyType
-
containsKey
Always returnstrue(all enum constants will always be present in the map).- Parameters:
key- the enum constant- Returns:
true- See Also:
-
containsValue
public boolean containsValue(int val) Returnstrueif this map contains the specified value.- Parameters:
val- the value to search for- Returns:
- whether the map contains the value
- See Also:
-
get
Returns the value to which the specified enum constant is mapped.- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped
- See Also:
-
put
Associates the specified value with the specified key in this map.- Parameters:
key- the keyval- the value enum constant yet.- See Also:
-
set
Likeput(), but provides a fluent API for adding entries to the map.- Parameters:
key- the keyval- the value- Returns:
- This instance
-
increment
Increments the value currently associated with the specified key.- Parameters:
key- the key- Returns:
- the new value associated with the key
-
add
Adds the specified value to the value currently associated with the specified key.- Parameters:
key- the keyval- the value to add to the value currently associated with the key- Returns:
- the new value associated with the key
-
multiply
Multiplies the value currently associated with the specified key with the specified value.- Parameters:
key- the keyval- the value to multiply with which to multiply the value currently associated with the key- Returns:
- the new value associated with the key
-
compute
Computes a new value for the value currently associated with the specified key- Parameters:
key- the keyoperator- the function to apply to the value currently associated with the key- Returns:
- the new value associated with the key
-
putAll
Adds all entries of the specified map to this map, overwriting any previous values.- Parameters:
other- theEnumToIntMapwhose key-value mappings to copy
-
putAll
Adds all entries of the specified map to this map. This method acts as a bridge to fully-generic map implementations.- Parameters:
other- theMapwhose key-value mappings to copynullValue- theintvalue to use fornullvalues in the source map
-
toGenericMap
-
keySet
Returns aSetview of the keys contained in this map. TheSetmaintains the order of the enum constants, and can be iterated over quickly, but is inefficient for typical set operations such asconstains().- Returns:
- a Set view of the keys contained in this map
- See Also:
-
values
Returns aCollectionview of the values contained in this map.- Returns:
- a
Collectionview of the values contained in this map - See Also:
-
intValues
Returns anIntListcontaining the values of this map.- Returns:
- an
IntListcontaining the values of this map
-
entrySet
-
forEach
Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.- Parameters:
action- the action to be performed for each entry- See Also:
-
isEmpty
public boolean isEmpty()Always returnsfalse.- Specified by:
isEmptyin interfaceorg.klojang.check.extra.Emptyable- Returns:
false
-
size
public int size()Returns the number of key-value mappings in this map.- Returns:
- the number of key-value mappings in this map
- See Also:
-
equals
-
hashCode
-
toString
-