Class ParameterSet
java.lang.Object
org.opentrafficsim.base.parameters.ParameterSet
- All Implemented Interfaces:
Parameters
Implementation of
Parameters with methods to initialize the set of parameters.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Wouter Schakel
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new, empty Parameters set.ParameterSet(Parameters parameters) Constructor which creates a copy of the input set. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(ParameterType<?> parameterType) Indicate whether the given parameter type has been set.<T> Optional<T>getOptionalParameter(ParameterType<T> parameterType) Returns a parameter value, ornullif not present.<T> TgetParameter(ParameterType<T> parameterType) Get parameter of given type.Map<ParameterType<?>,Object> Returns a safe copy of the parameters.voidresetParameter(ParameterType<?> parameterType) Resets the parameter value to the value from before the last resettable set.voidsetAllIn(Parameters params) Sets the parameters of this set in the given set.<T> voidsetClaimedParameter(ParameterType<T> parameterType, T value, Object key) Set parameter value of given parameter type.<T> ParameterSetsetDefaultParameter(ParameterType<T> parameter) Sets the default value of a parameter.setDefaultParameters(Class<?> clazz) Sets the default values of all accessible parameters defined in the given class.<T> voidsetParameter(ParameterType<T> parameterType, T value) Set parameter value of given parameter type.<T> voidsetParameterResettable(ParameterType<T> parameterType, T value) Set parameter value of given parameter type, store old value to allow a reset.toString()
-
Constructor Details
-
ParameterSet
public ParameterSet()Construct a new, empty Parameters set. -
ParameterSet
Constructor which creates a copy of the input set.- Parameters:
parameters- input set to copy into the new Parameters object
-
-
Method Details
-
setParameter
Description copied from interface:ParametersSet parameter value of given parameter type.- Specified by:
setParameterin interfaceParameters- Type Parameters:
T- class of value- Parameters:
parameterType- the parameter typevalue- new value for the parameter of typeparameterType- Throws:
ParameterException- if the value does not comply with value type constraints or is claimed
-
setClaimedParameter
public <T> void setClaimedParameter(ParameterType<T> parameterType, T value, Object key) throws ParameterException Description copied from interface:ParametersSet parameter value of given parameter type. This method claims setting the value by the key. No other key may be used to set the parameter.- Specified by:
setClaimedParameterin interfaceParameters- Type Parameters:
T- class of value- Parameters:
parameterType- the parameter typevalue- new value for the parameter of typeparameterTypekey- key object for unique right to set the parameter value- Throws:
ParameterException- if the value does not comply with value type constraints or is claimed by another key
-
setParameterResettable
public <T> void setParameterResettable(ParameterType<T> parameterType, T value) throws ParameterException Description copied from interface:ParametersSet parameter value of given parameter type, store old value to allow a reset. This method ignores any claim on the parameter, and should always be followed by a reset.- Specified by:
setParameterResettablein interfaceParameters- Type Parameters:
T- class of value- Parameters:
parameterType- the parameter typevalue- new value for the parameter of typeparameterType- Throws:
ParameterException- if the value does not comply with value type constraints
-
resetParameter
Description copied from interface:ParametersResets the parameter value to the value from before the last resettable set. This goes only a single value back.- Specified by:
resetParameterin interfaceParameters- Parameters:
parameterType- the parameter type- Throws:
ParameterException- if the parameter was never set
-
getParameter
Description copied from interface:ParametersGet parameter of given type.- Specified by:
getParameterin interfaceParameters- Type Parameters:
T- class of value- Parameters:
parameterType- the parameter type- Returns:
- parameter of the requested type if it exists
- Throws:
ParameterException- if the parameter was never set
-
getOptionalParameter
Description copied from interface:ParametersReturns a parameter value, ornullif not present. This can be used to prevent frequent calls to bothcontains()andgetParameter()in performance critical code.- Specified by:
getOptionalParameterin interfaceParameters- Type Parameters:
T- type of parameter value- Parameters:
parameterType- parameter type- Returns:
- parameter value, empty if not present
-
contains
Description copied from interface:ParametersIndicate whether the given parameter type has been set.- Specified by:
containsin interfaceParameters- Parameters:
parameterType- the parameter type to check- Returns:
- true if
parameterTypehas been set; false ifparameterTypehas not been set
-
getParameters
Returns a safe copy of the parameters.- Returns:
- a safe copy of the parameters, e.g., for printing
-
setDefaultParameter
Sets the default value of a parameter. Default value sets are not resettable.- Type Parameters:
T- Class of the value- Parameters:
parameter- the parameter to set the default value of- Returns:
- this set of parameters (for method chaining)
- Throws:
ParameterException- if the parameter type has no default value
-
setDefaultParameters
Sets the default values of all accessible parameters defined in the given class. Default value sets are not resettable.- Parameters:
clazz- class with parameters- Returns:
- this set of parameters (for method chaining)
-
setAllIn
Description copied from interface:ParametersSets the parameters of this set in the given set.- Specified by:
setAllInin interfaceParameters- Parameters:
params- parameters to set the values in
-
toString
-