Class HMap
java.lang.Object
com.jnape.palatable.lambda.adt.hmap.HMap
- All Implemented Interfaces:
Iterable<Tuple2<TypeSafeKey<?,
?>, Object>>
An immutable heterogeneous mapping from a parametrized type-safe key to any value, supporting a minimal mapping
interface.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate HMap
alter
(Consumer<Map<TypeSafeKey<?, ?>, Object>> alterFn) boolean
containsKey
(TypeSafeKey<?, ?> key) Determine if a key is mapped.<V> V
demand
(TypeSafeKey<?, V> key) Retrieve the value at this key, throwing aNoSuchElementException
if this key is unmapped.static HMap
Static factory method for creating an empty HMap.boolean
<A,
B> Maybe <B> get
(TypeSafeKey<A, B> key) Retrieve the value at this key.int
hashCode()
static <V1,
V2> HMap hMap
(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2) Static factory method for creating an HMap from two given associations.static <V1,
V2, V3>
HMaphMap
(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3) Static factory method for creating an HMap from three given associations.static <V1,
V2, V3, V4>
HMaphMap
(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4) Static factory method for creating an HMap from four given associations.static <V1,
V2, V3, V4, V5>
HMaphMap
(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5) Static factory method for creating an HMap from five given associations.static <V1,
V2, V3, V4, V5, V6>
HMaphMap
(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5, TypeSafeKey<?, V6> key6, V6 value6) Static factory method for creating an HMap from six given associations.static <V1,
V2, V3, V4, V5, V6, V7>
HMaphMap
(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5, TypeSafeKey<?, V6> key6, V6 value6, TypeSafeKey<?, V7> key7, V7 value7) Static factory method for creating an HMap from seven given associations.static <V1,
V2, V3, V4, V5, V6, V7, V8>
HMaphMap
(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5, TypeSafeKey<?, V6> key6, V6 value6, TypeSafeKey<?, V7> key7, V7 value7, TypeSafeKey<?, V8> key8, V8 value8) Static factory method for creating an HMap from eight given associations.boolean
isEmpty()
Test whether thisHMap
is empty.Iterator
<Tuple2<TypeSafeKey<?, ?>, Object>> iterator()
Set
<TypeSafeKey<?, ?>> keys()
Retrieve all the mapped keys.<V> HMap
put
(TypeSafeKey<?, V> key, V value) Store a value for the given key.Store all the key/value mappings inhMap
in this HMap.remove
(TypeSafeKey<?, ?> key) Remove a mapping from this HMap.Remove all the key/value mappings inhMap
from this HMap.static <V> HMap
singletonHMap
(TypeSafeKey<?, V> key, V value) Static factory method for creating a singleton HMap.Map
<TypeSafeKey<?, ?>, Object> toMap()
toString()
values()
Retrieve all the mapped values.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
EMPTY
-
table
-
-
Constructor Details
-
HMap
-
-
Method Details
-
get
Retrieve the value at this key.- Type Parameters:
A
- the value typeB
- the value type- Parameters:
key
- the key- Returns:
- Maybe the value at this key
-
demand
Retrieve the value at this key, throwing aNoSuchElementException
if this key is unmapped.- Type Parameters:
V
- the value type- Parameters:
key
- the key- Returns:
- the value at this key
- Throws:
NoSuchElementException
- if the key is unmapped
-
put
Store a value for the given key.- Type Parameters:
V
- the value type- Parameters:
key
- the keyvalue
- the value- Returns:
- the updated HMap
-
putAll
Store all the key/value mappings inhMap
in this HMap.- Parameters:
hMap
- the other HMap- Returns:
- the updated HMap
-
containsKey
Determine if a key is mapped.- Parameters:
key
- the key- Returns:
- true if the key is mapped; false otherwise
-
remove
Remove a mapping from this HMap.- Parameters:
key
- the key- Returns:
- the updated HMap
-
removeAll
Remove all the key/value mappings inhMap
from this HMap.- Parameters:
hMap
- the other HMap- Returns:
- the updated HMap
-
isEmpty
public boolean isEmpty()Test whether thisHMap
is empty.- Returns:
- true if the
HMap
is empty; false otherwise.
-
keys
Retrieve all the mapped keys.Note that unlike with
Map.keySet()
, the resulting key set is not "live"; in fact that is, alterations to the resulting key set have no effect on the backingHMap
.- Returns:
- a
Set
of all the mapped keys
-
values
Retrieve all the mapped values.- Returns:
- a
List
of all the mapped values
-
toMap
Return a standardMap
view of the current snapshot of thisHMap
. Note that updates to either theMap
view or to the originalHMap
do not propagate to the other.- Returns:
- the map view
-
iterator
- Specified by:
iterator
in interfaceIterable<Tuple2<TypeSafeKey<?,
?>, Object>>
-
equals
-
hashCode
public int hashCode() -
toString
-
alter
-
emptyHMap
Static factory method for creating an empty HMap.- Returns:
- an empty HMap
-
singletonHMap
Static factory method for creating a singleton HMap.- Type Parameters:
V
- the only mapped value type- Parameters:
key
- the only mapped keyvalue
- the only mapped value- Returns:
- a singleton HMap
-
hMap
public static <V1,V2> HMap hMap(TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2) Static factory method for creating an HMap from two given associations.- Type Parameters:
V1
- value1's typeV2
- value2's type- Parameters:
key1
- the first mapped keyvalue1
- the value mapped at key1key2
- the second mapped keyvalue2
- the value mapped at key2- Returns:
- an HMap with the given associations
-
hMap
public static <V1,V2, HMap hMapV3> (TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3) Static factory method for creating an HMap from three given associations.- Type Parameters:
V1
- value1's typeV2
- value2's typeV3
- value3's type- Parameters:
key1
- the first mapped keyvalue1
- the value mapped at key1key2
- the second mapped keyvalue2
- the value mapped at key2key3
- the third mapped keyvalue3
- the value mapped at key3- Returns:
- an HMap with the given associations
-
hMap
public static <V1,V2, HMap hMapV3, V4> (TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4) Static factory method for creating an HMap from four given associations.- Type Parameters:
V1
- value1's typeV2
- value2's typeV3
- value3's typeV4
- value4's type- Parameters:
key1
- the first mapped keyvalue1
- the value mapped at key1key2
- the second mapped keyvalue2
- the value mapped at key2key3
- the third mapped keyvalue3
- the value mapped at key3key4
- the fourth mapped keyvalue4
- the value mapped at key4- Returns:
- an HMap with the given associations
-
hMap
public static <V1,V2, HMap hMapV3, V4, V5> (TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5) Static factory method for creating an HMap from five given associations.- Type Parameters:
V1
- value1's typeV2
- value2's typeV3
- value3's typeV4
- value4's typeV5
- value5's type- Parameters:
key1
- the first mapped keyvalue1
- the value mapped at key1key2
- the second mapped keyvalue2
- the value mapped at key2key3
- the third mapped keyvalue3
- the value mapped at key3key4
- the fourth mapped keyvalue4
- the value mapped at key4key5
- the fifth mapped keyvalue5
- the value mapped at key5- Returns:
- an HMap with the given associations
-
hMap
public static <V1,V2, HMap hMapV3, V4, V5, V6> (TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5, TypeSafeKey<?, V6> key6, V6 value6) Static factory method for creating an HMap from six given associations.- Type Parameters:
V1
- value1's typeV2
- value2's typeV3
- value3's typeV4
- value4's typeV5
- value5's typeV6
- value6's type- Parameters:
key1
- the first mapped keyvalue1
- the value mapped at key1key2
- the second mapped keyvalue2
- the value mapped at key2key3
- the third mapped keyvalue3
- the value mapped at key3key4
- the fourth mapped keyvalue4
- the value mapped at key4key5
- the fifth mapped keyvalue5
- the value mapped at key5key6
- the sixth mapped keyvalue6
- the value mapped at key6- Returns:
- an HMap with the given associations
-
hMap
public static <V1,V2, HMap hMapV3, V4, V5, V6, V7> (TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5, TypeSafeKey<?, V6> key6, V6 value6, TypeSafeKey<?, V7> key7, V7 value7) Static factory method for creating an HMap from seven given associations.- Type Parameters:
V1
- value1's typeV2
- value2's typeV3
- value3's typeV4
- value4's typeV5
- value5's typeV6
- value6's typeV7
- value7's type- Parameters:
key1
- the first mapped keyvalue1
- the value mapped at key1key2
- the second mapped keyvalue2
- the value mapped at key2key3
- the third mapped keyvalue3
- the value mapped at key3key4
- the fourth mapped keyvalue4
- the value mapped at key4key5
- the fifth mapped keyvalue5
- the value mapped at key5key6
- the sixth mapped keyvalue6
- the value mapped at key6key7
- the seventh mapped keyvalue7
- the value mapped at key7- Returns:
- an HMap with the given associations
-
hMap
public static <V1,V2, HMap hMapV3, V4, V5, V6, V7, V8> (TypeSafeKey<?, V1> key1, V1 value1, TypeSafeKey<?, V2> key2, V2 value2, TypeSafeKey<?, V3> key3, V3 value3, TypeSafeKey<?, V4> key4, V4 value4, TypeSafeKey<?, V5> key5, V5 value5, TypeSafeKey<?, V6> key6, V6 value6, TypeSafeKey<?, V7> key7, V7 value7, TypeSafeKey<?, V8> key8, V8 value8) Static factory method for creating an HMap from eight given associations.- Type Parameters:
V1
- value1's typeV2
- value2's typeV3
- value3's typeV4
- value4's typeV5
- value5's typeV6
- value6's typeV7
- value7's typeV8
- value8's type- Parameters:
key1
- the first mapped keyvalue1
- the value mapped at key1key2
- the second mapped keyvalue2
- the value mapped at key2key3
- the third mapped keyvalue3
- the value mapped at key3key4
- the fourth mapped keyvalue4
- the value mapped at key4key5
- the fifth mapped keyvalue5
- the value mapped at key5key6
- the sixth mapped keyvalue6
- the value mapped at key6key7
- the seventh mapped keyvalue7
- the value mapped at key7key8
- the eighth mapped keyvalue8
- the value mapped at key8- Returns:
- an HMap with the given associations
-