public class NumericParamController extends java.lang.Object implements InputParamController, java.io.Serializable
Let controlling a numeric parameter. Thus it is possible to set a default but also a minimum and a maximum value. Moreover you can indicate whether the value of the parameter can be modified by the user or not after initialization.
Here is the logic applied by this controller for a numeric parameter:
null
will then be returned.This implementation aims to be generic enough to support most of the numeric parameters, but if the logic presented above is not enough or does not fit your needs, you are free to extend it and thus benefit of the implementation of most of the functions and attributes of this controller.
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowModification
Indicates whether the parameter can be modified.
|
protected java.lang.Number |
defaultValue
The default value.
|
protected java.lang.Number |
maxValue
The maximum value.
|
protected java.lang.Number |
minValue
The maximum value.
|
Constructor and Description |
---|
NumericParamController()
Create a numeric controller with no restriction.
|
NumericParamController(java.lang.Number defaultValue,
java.lang.Number minValue,
java.lang.Number maxValue,
boolean allowModification)
Create a controller for a numeric parameter.
|
Modifier and Type | Method and Description |
---|---|
boolean |
allowModification()
Tells whether the controlled parameter may be modified after initialization.
|
void |
allowModification(boolean allowModification)
Lets indicating whether the value of the parameter can be modified after initialization.
|
java.lang.Object |
check(java.lang.Object value)
Checks the value of the controlled parameter and builds a new object from this value.
|
java.lang.Object |
getDefault()
Returns the default value of the controlled parameter.
|
java.lang.Number |
getMaximum()
Gets the maximum value of this parameter.
|
java.lang.Number |
getMinimum()
Gets the minimum value of this parameter.
|
void |
reset(java.lang.Number defaultVal,
java.lang.Number minVal,
java.lang.Number maxVal)
Reset all fields in the same time.
|
void |
setDefault(java.lang.Number newDefaultValue)
Set the default value that the parameter must have if none is specified by the user.
|
void |
setMaximum(java.lang.Number newMaxValue)
Sets the maximum value of this parameter.
|
void |
setMinimum(java.lang.Number newMinValue)
Sets the minimum value of this parameter.
|
protected java.lang.Number minValue
protected java.lang.Number defaultValue
protected java.lang.Number maxValue
protected boolean allowModification
public NumericParamController()
A default, minimum and/or maximum value can be set after creation using setDefault(Number)
,
setMinimum(Number)
and setMaximum(Number)
. By default this parameter can always be modified,
but it can be forbidden using allowModification(boolean)
.
public NumericParamController(java.lang.Number defaultValue, java.lang.Number minValue, java.lang.Number maxValue, boolean allowModification)
Create a controller for a numeric parameter. The default and the maximum value are initialized with the given parameters. The third parameter allows also to forbid the modification of the parameter value by the user, if set to false.
A default and/or maximum value can be modified after creation using setDefault(Number)
and setMaximum(Number)
. The flag telling whether this parameter can be modified by the user
can be changed using allowModification(boolean)
.
defaultValue
- Value set by default to the parameter, when none is specified.minValue
- Minimum value that can be set. If a smaller value is provided by the user, an exception will be thrown by check(Object)
.maxValue
- Maximum value that can be set. If a bigger value is provided by the user, an exception will be thrown by check(Object)
.allowModification
- true to allow the user to modify this value when creating a job, false otherwise.public final java.lang.Number getMinimum()
null
if none has been specified.public void setMinimum(java.lang.Number newMinValue)
Warning !:
If the given value is bigger than the maximum
value,
the minimum will be set automatically to the maximum
value ;
the given one will then be ignored.
Warning 2:
If the default value is smaller than the new minimum
value,
the default will be set automatically to the new minimum
value.
newMinValue
- The new minimum value. null
is allowed ; it will remove the constraint on the minimumpublic final java.lang.Number getMaximum()
null
if none has been specified.public void setMaximum(java.lang.Number newMaxValue)
Warning 1:
If the given value is smaller than the minimum
value,
the maximum will be set automatically to the minimum
value ;
the given one will then be ignored.
Warning 2:
If the default value is bigger than the new maximum
value,
the default will be set automatically to the new maximum
value.
newMaxValue
- The new maximum value. null
is allowed ; it will remove the constraint on the maximumpublic java.lang.Object getDefault()
InputParamController
getDefault
in interface InputParamController
public void setDefault(java.lang.Number newDefaultValue)
Warning:
If the given value is not between the minimum
and the maximum
of this controller, the default value will be automatically set to the minimum
value.
newDefaultValue
- The new default value for this controller.
null
allowed ; null
will then be returned if a given parameter is not set by the userpublic void reset(java.lang.Number defaultVal, java.lang.Number minVal, java.lang.Number maxVal)
defaultVal
- Value set by default to the parameter, when none is specified.minVal
- Minimum value that can be set. If a smaller value is provided by the user, an exception will be thrown by check(Object)
.maxVal
- Maximum value that can be set. If a bigger value is provided by the user, an exception will be thrown by check(Object)
.public boolean allowModification()
InputParamController
allowModification
in interface InputParamController
public void allowModification(boolean allowModification)
allowModification
- true if the parameter value can be modified,
false otherwise.public java.lang.Object check(java.lang.Object value) throws UWSException
InputParamController
Checks the value of the controlled parameter and builds a new object from this value.
check
in interface InputParamController
value
- Parameter value to check.UWSException
- If the given value is strongly incorrect.