public class DurationParamController extends NumericParamController
Let controlling a duration 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.
This controller behaves like a NumericParamController
EXCEPT on two points:
Double
or Float
values will be truncated/rounded.String
expressing the duration in a different unit.
This string must be prefixed by a unit. See parseDuration(String)
(and its reverse operation toString(Long)
)
for more details.Modifier and Type | Field and Description |
---|---|
protected static long |
MULT_DAYS
Multiplication factor between milliseconds and days.
|
protected static long |
MULT_HOURS
Multiplication factor between milliseconds and hours.
|
protected static long |
MULT_MIN
Multiplication factor between milliseconds and minutes.
|
protected static long |
MULT_MONTHS
Multiplication factor between milliseconds and months.
|
protected static long |
MULT_SEC
Multiplication factor between milliseconds and seconds.
|
protected static long |
MULT_WEEKS
Multiplication factor between milliseconds and weeks.
|
protected static long |
MULT_YEARS
Multiplication factor between milliseconds and years.
|
protected static java.util.regex.Pattern |
PATTERN_DURATION
Pattern created with the Regular Expression of a valid duration string.
|
protected static java.lang.String |
REGEXP_DAYS
Regular Expression of all string allowed to mean DAYS.
|
protected static java.lang.String |
REGEXP_HOURS
Regular Expression of all string allowed to mean HOURS.
|
protected static java.lang.String |
REGEXP_MIN
Regular Expression of all string allowed to mean MINUTES.
|
protected static java.lang.String |
REGEXP_MONTHS
Regular Expression of all string allowed to mean MONTHS.
|
protected static java.lang.String |
REGEXP_MS
Regular Expression of all string allowed to mean MILLISECONDS.
|
protected static java.lang.String |
REGEXP_SEC
Regular Expression of all string allowed to mean SECONDS.
|
protected static java.lang.String |
REGEXP_WEEKS
Regular Expression of all string allowed to mean WEEKS.
|
protected static java.lang.String |
REGEXP_YEARS
Regular Expression of all string allowed to mean YEARS.
|
allowModification, defaultValue, maxValue, minValue
Constructor and Description |
---|
DurationParamController()
Create a parameter controller for duration value with no restriction.
|
DurationParamController(java.lang.Long defaultValue,
java.lang.Long minValue,
java.lang.Long maxValue,
boolean allowModification)
Create a controller for a parameter expressing a duration.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
check(java.lang.Object value)
Checks the value of the controlled parameter and builds a new object from this value.
|
long |
parseDuration(java.lang.String duration)
Parse the given duration string.
|
void |
setDefault(java.lang.Number newDefaultValue)
Cast the given value as a long value and call
NumericParamController.setDefault(Number) . |
void |
setMaximum(java.lang.Number newMaxValue)
Cast the given value as a long value and call
NumericParamController.setMaximum(Number) . |
void |
setMinimum(java.lang.Number newMinValue)
Cast the given value as a long value and call
NumericParamController.setMinimum(Number) . |
java.lang.String |
toString(java.lang.Long duration)
Convert a duration value (expressed in milliseconds) into the best human readable unit value.
|
allowModification, allowModification, getDefault, getMaximum, getMinimum, reset
protected static final long MULT_SEC
A second is here defined as 1000 milliseconds. So the value is computed as follows: 1000.
protected static final long MULT_MIN
A minute is here defined as 60 seconds. So the value is computed as follows: MULT_SEC
*60.
protected static final long MULT_HOURS
An hour is here defined as 60 minutes. So the value is computed as follows: MULT_MIN
*60.
protected static final long MULT_DAYS
A day is here defined as 24 hours. So the value is computed as follows: MULT_HOURS
*24.
protected static final long MULT_WEEKS
A week is here defined as 7 days. So the value is computed as follows: MULT_DAYS
*7.
protected static final long MULT_MONTHS
A month is here defined as 30 days. So the value is computed as follows: MULT_DAYS
*30.
protected static final long MULT_YEARS
A year is here defined as 365 days. So the value is computed as follows: MULT_DAYS
*365.
protected static java.lang.String REGEXP_MS
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.lang.String REGEXP_SEC
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.lang.String REGEXP_MIN
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.lang.String REGEXP_HOURS
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.lang.String REGEXP_DAYS
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.lang.String REGEXP_WEEKS
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.lang.String REGEXP_MONTHS
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.lang.String REGEXP_YEARS
Important: opening and closing brackets are omitted here for a better integration
in the duration string's regular expression (see PATTERN_DURATION
).
protected static java.util.regex.Pattern PATTERN_DURATION
Such string MUST be a positive integer/long value eventually suffixed by a unit. Allowed unit strings are the following:
Important: Units are case sensitive!
Note: Space characters are ignored only if leading or trailing the whole string, or if between the duration and its unit.
public DurationParamController()
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 NumericParamController.allowModification(boolean)
.
public DurationParamController(java.lang.Long defaultValue, java.lang.Long minValue, java.lang.Long maxValue, boolean allowModification)
Create a controller for a parameter expressing a duration. The default and the maximum value are initialized with the given parameters (expressed in milliseconds). 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 NumericParamController.allowModification(boolean)
.
Important note: Values given in this constructor MUST be expressed in milliseconds.
defaultValue
- Value (in ms) set by default to the parameter, when none is specified.minValue
- Minimum value (in ms) that can be set. If a smaller value is provided by the user, an exception will be thrown by check(Object)
.maxValue
- Maximum value (in ms) 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 void setDefault(java.lang.Number newDefaultValue)
NumericParamController.setDefault(Number)
.setDefault
in class NumericParamController
newDefaultValue
- The new default value for this controller.
null
allowed ; null
will then be returned if a given parameter is not set by the userNumericParamController.setMinimum(java.lang.Number)
public void setMinimum(java.lang.Number newMinValue)
NumericParamController.setMinimum(Number)
.setMinimum
in class NumericParamController
newMinValue
- The new minimum value. null
is allowed ; it will remove the constraint on the minimumNumericParamController.setMinimum(java.lang.Number)
public void setMaximum(java.lang.Number newMaxValue)
NumericParamController.setMaximum(Number)
.setMaximum
in class NumericParamController
newMaxValue
- The new maximum value. null
is allowed ; it will remove the constraint on the maximumNumericParamController.setMinimum(java.lang.Number)
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
check
in class NumericParamController
value
- Parameter value to check.UWSException
- If the given value is strongly incorrect.public long parseDuration(java.lang.String duration) throws java.text.ParseException
Such string MUST be a positive integer/long value eventually suffixed by a unit. Allowed unit strings are the following:
Important: Units are case sensitive!
Note: Space characters are ignored only if leading or trailing the whole string, or if between the duration and its unit.
duration
- The duration string.-1
if the given string is null
or negative.java.text.ParseException
- If the given string is using an unknown unit string,
or if the string does not start digits.toString(Long)
public java.lang.String toString(java.lang.Long duration)
duration
- A duration in milliseconds.null
,
or a string expressing the given duration in the best integer value with a unit suffix.parseDuration(String)