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.
public final class DataMap<K> extends Object
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 parameterT
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DataMap.DataKey<K extends DataMap.DataKey<K,T>,T>
A key for type-safe access into aDataMap
.static class
DataMap.SimpleDataKey<T>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
get(DataMap.DataKey<? extends K,? extends T> key)
Retrieves the data currently mapped to the key.boolean
isSet(DataMap.DataKey<? extends K,?> key)
Returns true if the given key has a non-null value in the map.static <K> DataMap<K>
newDataMap()
<T> T
set(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 Detail
-
set
public <T> T set(DataMap.DataKey<? extends K,? super T> key, T data)
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
public <T> T get(DataMap.DataKey<? extends K,? extends T> key)
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)
-
isSet
public boolean isSet(DataMap.DataKey<? extends K,?> key)
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
public static <K> DataMap<K> newDataMap()
-
simpleDataKey
public static <T> DataMap.SimpleDataKey<T> simpleDataKey(String name)
-
-