Package net.sourceforge.pmd.util
Class DataMap<K>
java.lang.Object
net.sourceforge.pmd.util.DataMap<K>
- Type Parameters:
K- Type of keys in this map.
An opaque, strongly typed heterogeneous data container. Data maps can
be set to accept only a certain type of key, with the type parameter.
The key can itself constrain the type of values, using its own type
parameter
T.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDataMap.DataKey<K extends DataMap.DataKey<K,T>, T> A key for type-safe access into aDataMap.static class -
Method Summary
Modifier and TypeMethodDescription<T> Tcompute(DataMap.DataKey<? extends K, T> key, Function<? super @Nullable T, ? extends T> function) Create or replace a mapping with a value computed from the current value (or null if missing).<T> TcomputeIfAbsent(DataMap.DataKey<? extends K, T> key, Supplier<? extends T> supplier) Retrieve the value, or compute it if it is missing.<T> @Nullable Tget(DataMap.DataKey<? extends K, ? extends T> key) Retrieves the data currently mapped to the key.<T> TgetOrDefault(DataMap.DataKey<? extends K, ? extends T> key, T defaultValue) booleanisSet(DataMap.DataKey<? extends K, ?> key) Returns true if the given key has a non-null value in the map.<T> Tmerge(DataMap.DataKey<? extends K, T> key, T value, BiFunction<? super @NonNull T, ? super T, ? extends T> function) static <K> DataMap<K><T> @Nullable Tset(DataMap.DataKey<? extends K, ? super T> key, T data) Set the mapping to the given data.static <T> DataMap.SimpleDataKey<T>simpleDataKey(String name)
-
Method Details
-
set
Set the mapping to the given data.- Type Parameters:
T- Type of the data- Parameters:
key- Keydata- Data mapped to the key- Returns:
- Previous value associated with the key (nullable)
-
get
Retrieves the data currently mapped to the key.- Type Parameters:
T- Type of the data- Parameters:
key- Key- Returns:
- Value associated with the key (nullable)
-
getOrDefault
-
computeIfAbsent
Retrieve the value, or compute it if it is missing.- Type Parameters:
T- Type of the data- Parameters:
key- Keysupplier- Supplier for a value- Returns:
- Value associated with the key (as nullable as the
-
compute
public <T> T compute(DataMap.DataKey<? extends K, T> key, Function<? super @Nullable T, ? extends T> function) Create or replace a mapping with a value computed from the current value (or null if missing).- Type Parameters:
T- Type of the data- Parameters:
key- Keyfunction- Supplier for a value- Returns:
- Value returned by the parameter function
-
merge
public <T> T merge(DataMap.DataKey<? extends K, T> key, T value, BiFunction<? super @NonNull T, ? super T, ? extends T> function) - See Also:
-
isSet
Returns true if the given key has a non-null value in the map.- Parameters:
key- Key- Returns:
- True if some value is set
-
newDataMap
-
simpleDataKey
-