Class ConditionalParameterManager<T>
- Type Parameters:
T- the type of the main parameter's value used in the conditions
ConditionalParameter objects associated with a main parameter in
a multi-objective metaheuristic parameter space.
This class serves as a registry and coordinator for conditional parameters, enabling flexible and adaptive parameter configurations where certain parameters are only relevant when a parent parameter satisfies specific conditions. It supports both custom predicate-based conditions and common value-based equality conditions.
The manager handles the dynamic activation of parameters during parameter space processing, automatically parsing arguments only for parameters whose conditions are satisfied by the current value of the main parameter.
Example usage scenario:
// For a categorical parameter "algorithmVariant" with values "basic" and "advanced"
ConditionalParameterManager<String> manager = new ConditionalParameterManager<>();
// Add parameters that only apply to "advanced" variant
manager.addConditionalParameter("advanced", archiveSize);
manager.addConditionalParameter("advanced", selectionPressure);
// During processing, only parse arguments for active parameters
manager.parseConditionalParameters("advanced", args);
This class is particularly useful for processing YAML configuration files where parameters have nested conditional structures, allowing for dynamic parameter space exploration based on parent parameter values.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- [Author Name]
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConditionalParameter(boolean value, Parameter<?> parameter) Adds a conditional parameter that becomes active when the main parameter equals the specified boolean value.voidaddConditionalParameter(int value, Parameter<?> parameter) Adds a conditional parameter that becomes active when the main parameter equals the specified integer value.voidaddConditionalParameter(String value, Parameter<?> parameter) Adds a conditional parameter that becomes active when the main parameter equals the specified string value.voidaddConditionalParameter(Predicate<T> condition, Parameter<?> parameter, String description) Adds a conditional parameter with a custom predicate condition.Returns an unmodifiable view of all managed conditional parameters.Parameter<?> findConditionalParameter(String parameterName) Finds a conditional parameter by its name.voidparseConditionalParameters(T value, String[] args) Parses arguments for all conditional parameters whose conditions are satisfied by the given main parameter value.
-
Constructor Details
-
ConditionalParameterManager
public ConditionalParameterManager()
-
-
Method Details
-
addConditionalParameter
public void addConditionalParameter(Predicate<T> condition, Parameter<?> parameter, String description) Adds a conditional parameter with a custom predicate condition.This method provides maximum flexibility by allowing any predicate-based condition to determine when the parameter becomes active. The condition will be evaluated against the main parameter's value during parameter space processing.
- Parameters:
condition- the predicate that determines when the parameter is active; must not be nullparameter- the parameter to be activated when the condition is met; must not be nulldescription- a textual description of the condition for documentation, debugging, and logging purposes; must not be null- Throws:
IllegalArgumentException- if any parameter is null (via ConditionalParameter constructor)
-
addConditionalParameter
Adds a conditional parameter that becomes active when the main parameter equals the specified string value.This is a convenience method for the common case where a parameter should only be active when the main parameter has a specific string value. The condition uses
Object.equals(Object)for comparison.Note: This method assumes the main parameter type
Tcan be meaningfully compared with a String. IfTis not String-compatible, this may result in the condition never being satisfied.- Parameters:
value- the string value that activates the parameter; must not be nullparameter- the parameter to be activated; must not be null
-
addConditionalParameter
Adds a conditional parameter that becomes active when the main parameter equals the specified integer value.This is a convenience method for the common case where a parameter should only be active when the main parameter has a specific integer value. The condition uses
Object.equals(Object)for comparison.Note: This method assumes the main parameter type
Tcan be meaningfully compared with an Integer. IfTis not Integer-compatible, this may result in the condition never being satisfied.- Parameters:
value- the integer value that activates the parameterparameter- the parameter to be activated; must not be null
-
addConditionalParameter
Adds a conditional parameter that becomes active when the main parameter equals the specified boolean value.This is a convenience method for the common case where a parameter should only be active when the main parameter has a specific boolean value. The condition uses
Object.equals(Object)for comparison.Note: This method assumes the main parameter type
Tcan be meaningfully compared with a Boolean. IfTis not Boolean-compatible, this may result in the condition never being satisfied.- Parameters:
value- the boolean value that activates the parameterparameter- the parameter to be activated; must not be null
-
parseConditionalParameters
Parses arguments for all conditional parameters whose conditions are satisfied by the given main parameter value.This method iterates through all managed conditional parameters, evaluates their conditions against the provided value, and calls
Parameter.parse(String[])only on those parameters whose conditions returntrue.This enables dynamic parameter processing where only relevant parameters are considered based on the current configuration state.
- Parameters:
value- the current value of the main parameter to test conditions againstargs- the command-line arguments or configuration values to parse for the active parameters
-
findConditionalParameter
Finds a conditional parameter by its name.This method searches through all managed conditional parameters and returns the first parameter whose name matches the specified parameter name.
Return behavior: This method returns
nullif no parameter with the given name is found. Callers should check for null return values before using the result.- Parameters:
parameterName- the name of the parameter to find; must not be null- Returns:
- the
Parameterwith the given name, ornullif no parameter with the specified name is found
-
conditionalParameters
Returns an unmodifiable view of all managed conditional parameters.The returned list contains all
ConditionalParameterobjects that have been registered with this manager. This method is useful for introspection, validation, and debugging purposes.The returned list reflects the current state of the manager and will include any parameters added after this method is called, but modifications to the returned list will not affect the manager's internal state.
- Returns:
- the list of all managed
ConditionalParameterobjects; never null, but may be empty
-