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
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final BiFunction<BindingContext,Object, List<Problem>> -
Constructor Summary
ConstructorsConstructorDescriptionParameter(@NonNull String name, @NonNull Class<?> type, @NonNull Optional<BiFunction<BindingContext, Parameter, List<?>>> function, int min, int max) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected Parameterclone(Consumer<Parameter.MutableFields> mutator) booleangetArity()@NonNull Optional<BiFunction<BindingContext,Parameter, List<?>>> List<?>getDefaultValues(BindingContext modelContext) intint@NonNull StringgetName()@NonNull Class<?>getType()@NonNull BiFunction<BindingContext,Object, List<Problem>> booleanhasCorrectArity(int numValues) booleaninthashCode()booleanisMany()booleanstatic Parameterstatic Parameterstatic <T> ParameterConstructs aParameterwith a specific min and max number of parameters and no defaultsstatic <T> Parameterstatic <T> ParametertoString()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
Parameterwith 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
-