Package org.djutils.multikeymap
Class MultiKeyMap<T>
java.lang.Object
org.djutils.multikeymap.MultiKeyMap<T>
- Type Parameters:
T
- value type
Store for data indexed by a combination of objects. An important difference with a normal (Linked-)HashMap is that the
getValue
method has a Supplier
argument that will be invoked when no value was stored under the
provided combination of keys. The value yielded by the Supplier
is then stored under that key combination. If
this behavior is not wanted, the user can provide the null value for the Supplier
argument. The map can store
null values, but on retrieval these are indistinguishable from values that were never set. No key values may be null.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionClears the mapping for a key combination.Retrieve a value from this MultiKeyMap.Retrieve a value from this MultiKeyMap.Return set of key objects on this level.Retrieve a sub map.Put (add or replace) a value in this MultiKeyMap.toString()
-
Constructor Details
-
MultiKeyMap
Construct a new MultiKeyMap.- Parameters:
keyTypes
- Class<?>...; the types of the keys
-
-
Method Details
-
get
Retrieve a value from this MultiKeyMap. Can create a new entry if it does not exist yet.- Parameters:
supplier
- Supplier<T>; supplier ofT
in case the leaf does not exist yet. Set this tonull
to suppress creation of new branches and a new leafkeys
- Object...; list of key objects- Returns:
- T; the existing value, or the value that was obtained through the
supplier
. Returnsnull
if the leaf does not exist andsupplier
isnull
-
get
Retrieve a value from this MultiKeyMap.- Parameters:
keys
- Object...; the key objects- Returns:
- T; value, or null if no value is stored under the provided key objects
-
getSubMap
Retrieve a sub map.- Parameters:
keys
- Object...; the key objects (must be at least one item shorter than the full depth)- Returns:
- MultiKeyMap<T>; the sub map
-
put
Put (add or replace) a value in this MultiKeyMap.- Parameters:
newValue
- T; the new valuekeys
- Object...; the key objects- Returns:
- T; the previous value stored under the key objects, or null if no value was currently stored under the key objects
-
getKeys
Return set of key objects on this level.- Parameters:
keys
- Object...; list of key objects (may be empty to select the key set at the top level- Returns:
- Set; set of key objects on this level. This is not a safe copy; this set reflects subsequent changes in this MultiKeyMap and modifying this set would modify this MultiKeyMap (potentially making it inconsistent).
-
clear
Clears the mapping for a key combination.- Parameters:
keys
- Object...; key combination to clear the map for- Returns:
- Object; object that was previously mapped to the key combination, or
null
if it was not cached.
-
toString
-