Package com.gengoai
Class ParamMap<V extends ParamMap<V>>
- java.lang.Object
-
- com.gengoai.ParamMap<V>
-
- Type Parameters:
V
- the type parameter
- All Implemented Interfaces:
Copyable<V>
,Serializable
public class ParamMap<V extends ParamMap<V>> extends Object implements Serializable, Copyable<V>
A parameter m
- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ParamMap.Parameter<T>
Represents aParameterDef
and its value within aParamMap
.
-
Constructor Summary
Constructors Constructor Description ParamMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <Z extends V>
Zas(@NonNull Class<Z> zClass)
Attempts to cast this ParamMap as child class.V
copy()
Makes a copy of this object.<T> T
get(@NonNull ParameterDef<T> param)
Gets the value of the givenParameterDef
<T> T
get(String param)
Gets the value of the givenParameterDef
name<T> T
getOrDefault(@NonNull ParameterDef<T> param, T defaultValue)
Gets the value of the givenParameterDef
or the default value if the Param is not in the map<T> T
getOrDefault(String param, T defaultValue)
Gets the value of the givenParameterDef
or the default value if the Param is not in the map<T> ParameterDef<T>
getParam(String name)
Gets theParameterDef
with the given name in the map.<T> ParamMap.Parameter<T>
parameter(@NonNull ParameterDef<T> param, T defValue)
Creates aParamMap.Parameter
of the givenParameterDef
with the given default value registering it with thisParamMap
and returning the created Parameter.Set<String>
parameterNames()
Gets the parameter names associated with this ParamMap<T> V
set(@NonNull ParameterDef<T> param, T value)
Sets the value for the given parameter<T> V
set(String param, T value)
Sets the value for the given parameter<T> T
setAll(@NonNull ParamMap<V> paramMap)
Sets all values on this parameter map to those on the given parameter.String
toString()
V
update(@NonNull Consumer<V> updater)
Updates the ParamMap using the given consumer.
-
-
-
Method Detail
-
as
public <Z extends V> Z as(@NonNull @NonNull Class<Z> zClass)
Attempts to cast this ParamMap as child class.- Type Parameters:
Z
- the child type parameter- Parameters:
zClass
- the child class- Returns:
- this map as the given Child class
- Throws:
IllegalArgumentException
- if this class is not an instance of the given child class
-
get
public <T> T get(@NonNull @NonNull ParameterDef<T> param)
Gets the value of the givenParameterDef
- Type Parameters:
T
- the type of the Param parameter- Parameters:
param
- the param whose value we want- Returns:
- the value of the param
- Throws:
IllegalArgumentException
- if the parm is unknown to this map
-
get
public <T> T get(String param)
Gets the value of the givenParameterDef
name- Type Parameters:
T
- the type of the Param parameter- Parameters:
param
- the param whose value we want- Returns:
- the value of the param
- Throws:
IllegalArgumentException
- if the parm is unknown to this map
-
getOrDefault
public <T> T getOrDefault(@NonNull @NonNull ParameterDef<T> param, T defaultValue)
Gets the value of the givenParameterDef
or the default value if the Param is not in the map- Type Parameters:
T
- the type of the Param parameter- Parameters:
param
- the param whose value we wantdefaultValue
- the default value to return if the param is not in the map- Returns:
- the value of the param or the default value if the Param is not in the map
-
getOrDefault
public <T> T getOrDefault(String param, T defaultValue)
Gets the value of the givenParameterDef
or the default value if the Param is not in the map- Type Parameters:
T
- the type of the Param parameter- Parameters:
param
- the param whose value we wantdefaultValue
- the default value to return if the param is not in the map- Returns:
- the value of the param or the default value if the Param is not in the map
-
getParam
public <T> ParameterDef<T> getParam(String name)
Gets theParameterDef
with the given name in the map.- Type Parameters:
T
- the Param type parameter- Parameters:
name
- the name of the param- Returns:
- the param
- Throws:
IllegalArgumentException
- if the parm is unknown to this map
-
parameter
public <T> ParamMap.Parameter<T> parameter(@NonNull @NonNull ParameterDef<T> param, T defValue)
Creates aParamMap.Parameter
of the givenParameterDef
with the given default value registering it with thisParamMap
and returning the created Parameter.- Type Parameters:
T
- the parameter type parameter- Parameters:
param
- the parameter definitiondefValue
- the default value- Returns:
- the parameter
-
parameterNames
public Set<String> parameterNames()
Gets the parameter names associated with this ParamMap- Returns:
- the set
-
set
public <T> V set(@NonNull @NonNull ParameterDef<T> param, T value)
Sets the value for the given parameter- Type Parameters:
T
- the type parameter- Parameters:
param
- the paramvalue
- the value- Returns:
- this ParamMap
-
set
public <T> V set(String param, T value)
Sets the value for the given parameter- Type Parameters:
T
- the type parameter- Parameters:
param
- the paramvalue
- the value- Returns:
- this ParamMap
-
setAll
public <T> T setAll(@NonNull @NonNull ParamMap<V> paramMap)
Sets all values on this parameter map to those on the given parameter. It will ignore any parameters not defined on this parameter map.- Type Parameters:
T
- the parameter map type parameter- Parameters:
paramMap
- the parameter map- Returns:
- this ParameterMap
-
-