public class NumberConstraints extends Object implements Constraints
Modifier and Type | Field and Description |
---|---|
static NumberFormat |
DEFAULT_FORMAT
Default format to use for number parsing.
|
protected NumberFormat |
format |
protected Number |
max |
protected Number |
min |
protected StringSet[] |
uNames |
protected Pattern |
uPattern |
protected Number[] |
uValues |
Constructor and Description |
---|
NumberConstraints()
Default constructor.
|
NumberConstraints(Locale locale,
String min,
String max,
boolean allowDecimals,
boolean useGrouping,
String unitPattern,
String unitNames,
String unitValues)
Creates a number constraints enforcement entity.
|
Modifier and Type | Method and Description |
---|---|
NumberFormat |
getFormat()
Get the number format associated with this constraint.
|
Number |
getUnitBasedValue(Number n,
String unit)
Get the number value adjusted with the corresponding factor of the
given unit specifier.
|
String |
getUnitName(String token)
Get the post-fix unit specifier portion of the given token
|
boolean |
isValid(Serializable o)
Determines whether or not the given object is valid in the context of
these constraints.
|
public static final NumberFormat DEFAULT_FORMAT
protected NumberFormat format
protected Number min
protected Number max
protected Pattern uPattern
protected StringSet[] uNames
protected Number[] uValues
public NumberConstraints()
public NumberConstraints(Locale locale, String min, String max, boolean allowDecimals, boolean useGrouping, String unitPattern, String unitNames, String unitValues)
locale
- context locale for validationmin
- If not null, it specifies the minimum numerical value the
parsed argument can have to be a valid parameter.max
- If not null, it specifies the maximum numerical value the
parsed argument can have to be a valid parameter.allowDecimals
- Boolean indicating whether decimal values are
allowed.useGrouping
- Boolean indicating whether grouping separator isunitPattern
- regexp pattern for finding the start of units;
defaults to [:alpha:] character set allowed.unitNames
- comma-separated list of string-setsunitValues
- comma-separated list of unit multiplier valuespublic NumberFormat getFormat()
NumberFormat
instance.public String getUnitName(String token)
token
- string from which the post-fix unit specifier should be
extractedpublic Number getUnitBasedValue(Number n, String unit)
n
- base number value to be adjustedunit
- unit specifier whose corresponding factor should be used to
adjust the number valuepublic boolean isValid(Serializable o)
Constraints
isValid
in interface Constraints
o
- object to be validated against the constraintsCopyright © 2015. All Rights Reserved.