Class Parameter
Parameters are the inputs and toggles that ultimately control how Riskscape works. They are used by the data and modelling constructs to allow users to customize and inspect how riskscape works.
Care has been taken to make this API usable from jvm languages other than Java, and so does not rely on language features such as annotations for their definition (although those are available as an add on convenience for java programmers)
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final BiFunction<BindingContext,
Object, List<Problem>> -
Constructor Summary
ConstructorDescriptionParameter
(@NonNull String name, @NonNull Class<?> type, @NonNull Optional<BiFunction<BindingContext, Parameter, List<?>>> function, int min, int max) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
protected Parameter
clone
(Consumer<Parameter.MutableFields> mutator) boolean
getArity()
@NonNull Optional<BiFunction<BindingContext,
Parameter, List<?>>> List<?>
getDefaultValues
(BindingContext modelContext) int
int
@NonNull String
getName()
@NonNull Class<?>
getType()
@NonNull BiFunction<BindingContext,
Object, List<Problem>> boolean
hasCorrectArity
(int numValues) boolean
int
hashCode()
boolean
isMany()
boolean
static Parameter
static Parameter
static <T> Parameter
Constructs aParameter
with a specific min and max number of parameters and no defaultsstatic <T> Parameter
static <T> Parameter
toString()
validate
(BindingContext context, Object boundValue) Performs optional additional validation on a value bound to this parameter.withNewDefaults
(BiFunction<BindingContext, Parameter, List<?>> newDefaultFunction) Builds a new Parameter based on this one, but with new default value(s)withNewName
(String newName) withNewType
(Class<?> newType) withValidation
(BiFunction<BindingContext, Object, List<Problem>> validationFunction)
-
Field Details
-
NO_DEFAULT
- See Also:
-
NO_VALIDATION
-
-
Constructor Details
-
Parameter
public Parameter(@NonNull @NonNull String name, @NonNull @NonNull Class<?> type, @NonNull @NonNull Optional<BiFunction<BindingContext, Parameter, List<?>>> function, int min, int max) - Parameters:
name
- The name that identifies this parameter among others on the modeltype
- The java type of this parameter.function
- a function that can return a default value for this parameter
-
-
Method Details
-
required
-
required
-
range
Constructs a
Parameter
with a specific min and max number of parameters and no defaults -
optional
-
optional
-
clone
-
getDefaultValues
- Throws:
ParameterBindingException
-
isOptional
public boolean isOptional()- Returns:
- true if a value is not required for this parameter, e.g. the model should be able to run without it
-
isMany
public boolean isMany()- Returns:
- true if this parameter supports more than one value, e.g. a list or a set.
-
hasDefaultValue
public boolean hasDefaultValue()- Returns:
- true if this parameter has a default value set, e.g. getDefaultValues() should return at least one object
-
withNewDefaults
Builds a new Parameter based on this one, but with new default value(s)
- Parameters:
newDefaultFunction
- a function that yields new default values- Returns:
- a new parameter.
-
withNewName
-
getTypeName
-
getArity
-
hasCorrectArity
public boolean hasCorrectArity(int numValues) -
toString
-
withNewType
- Returns:
- a clone of this parameter with the type set to
newType
-
withValidation
- Returns:
- a clone of this parameter with additional validation of the value supplied for the parameter
-
validate
Performs optional additional validation on a value bound to this parameter. E.g. the parameter might expect not only an integer value, but a value between 1 and 100.
- Returns:
- a list of problems, if the bound value is invalid
-
getType
-
getDefaultFunction
@NonNull public @NonNull Optional<BiFunction<BindingContext,Parameter, getDefaultFunction()List<?>>> -
getMinRequired
public int getMinRequired() -
getMaxRequired
public int getMaxRequired() -
getValidation
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getName
-