public class IntegerPropertyType extends PropertyType<Integer> implements Range<Integer>
java.lang.Integer
. Integer.parseInt(string)
.
Constructor Example | Comments | ||
---|---|---|---|
Property<Integer> A_PROPERTY = new Property<Integer>("name", new IntegerPropertyType()); |
No default value, no minimum or maximum constraints. | ||
Property<Integer> A_PROPERTY = |
Default value is "25", no minimum or maximum constraints. | ||
Property<Integer> A_PROPERTY = |
No default value,minimum is "0" and maximum is "50", both inclusive.. | ||
Property<Integer> A_PROPERTY = |
Default value is "25",minimum is "0" and maximum is "50", both inclusive. | ||
Type of value(s) | Examples | Result | Comments |
Valid | -25 | new Integer(-25) | Validate successfully. |
Valid | 34 | new Integer(34) | Validate successfully. |
Invalid | cow | null |
Validate will throw an exception. The resulting value is null . |
Invalid | 3.23 | null |
|
Invalid | «empty string» | null |
|
Invalid | «empty string after trim» | null |
|
Invalid | null |
defaultValue OR null |
Validate will throw an exception. Return default value if set, otherwise null . |
Integer.parseInt(String)
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
TYPE
The type name string constant of IntegerPropertyType.
|
Constructor and Description |
---|
IntegerPropertyType()
Default constructor, no minimum, maximum or default value.
|
IntegerPropertyType(int defaultValue)
Constructor with default value.
|
IntegerPropertyType(Integer defaultValue)
Constructor with default value.
|
IntegerPropertyType(Integer minValue,
Integer maxValue)
Constructor with minimum and maximum value.
|
IntegerPropertyType(Integer defaultValue,
Integer minValue,
Integer maxValue)
Constructor with minimum and maximum value.
|
IntegerPropertyType(int minValue,
int maxValue)
Constructor with minimum and maximum value.
|
IntegerPropertyType(int defaultValue,
int minValue,
int maxValue)
Constructor with minimum, maximum and default value.
|
Modifier and Type | Method and Description |
---|---|
Integer |
getMaxValue()
Gets the max value (inclusive) a value may be.
|
Integer |
getMinValue()
Gets the min value (inclusive) a value may be.
|
List<String> |
getRestrictions()
Gets a detailed description of the PropertyType with any constraints that might influence the validation.
|
boolean |
isUseMaxValue()
Determines if max value restriction is used.
|
boolean |
isUseMinValue()
Determines if min value restriction is used.
|
void |
setMaxValue(Integer maxValue)
Sets the max value (inclusive) a value may be.
|
void |
setMinValue(Integer minValue)
Sets the min value (inclusive) a value may be.
|
void |
validateConstraints(String propertyName)
A PropertyType can have some constraints here is where they are
validated.
|
void |
validateIsInRange(String propertyName,
Integer value)
Validates that a value is inside the valid range of min and max value if defined.
|
void |
validateMinMaxValues(String propertyName)
Validates that minValue is less or equal to maxValue, must be called by validateConstraints, and if there is a default value that is inside the valid range.
|
Integer |
validateValue(String propertyName,
String value)
Converts the string representation of to a typed value.
|
equals, getDefaultValue, getDefaultValueAsString, getDefaultValueDescription, getDescription, getDescription, getInitializationPriority, getIo, getLogger, getTypeName, hasDefaultValue, isDefaultValueValid, postGetValueProcessing, setDefaultValue, setInitializationPriority, setIo, setTypedValue, setTypeName, toString, toType, validate, validateNullType
public static final String TYPE
public IntegerPropertyType()
public IntegerPropertyType(int defaultValue)
defaultValue
- default value returned if property value is undefined.public IntegerPropertyType(Integer defaultValue)
defaultValue
- default value returned if property value is undefined.public IntegerPropertyType(int minValue, int maxValue)
minValue
- minimum value, inclusive.maxValue
- maximum value, inclusive.public IntegerPropertyType(int defaultValue, int minValue, int maxValue)
defaultValue
- default value returned if property value is undefined.minValue
- minimum value, inclusive.maxValue
- maximum value, inclusive.public IntegerPropertyType(Integer minValue, Integer maxValue)
minValue
- minimum value, inclusive, if is null
than it means no default value.maxValue
- maximum value, inclusive, if is null
than it means no default value.public IntegerPropertyType(Integer defaultValue, Integer minValue, Integer maxValue)
defaultValue
- default value returned if property value is undefined.minValue
- minimum value, inclusive, if is null
than it means no default value.maxValue
- maximum value, inclusive, if is null
than it means no default value.public List<String> getRestrictions()
PropertyType
getRestrictions
in class PropertyType<Integer>
public Integer validateValue(String propertyName, String value) throws PropertyException
PropertyType
validateValue
in class PropertyType<Integer>
propertyName
- the name of the property used for logging purposes. To uniquely identify the Property with validation issues.value
- the string representation of the propertyPropertyException
- if the conversion failed.public void validateConstraints(String propertyName) throws PropertyException
PropertyType
validateConstraints
in class PropertyType<Integer>
propertyName
- the name of the property used for logging purposes, to
identify the unique property which PropertyType has constraint
issues.PropertyException
- if the constraints have invalid/conflicting values.Property.validate()
public void validateIsInRange(String propertyName, Integer value) throws PropertyException
Range
validateIsInRange
in interface Range<Integer>
propertyName
- the propertyvalue
- the valuePropertyException
- if minValue is not null
and value is less than, or maxValue is not null
and value is greather than.PropertyType.validateValue(String, String)
public void validateMinMaxValues(String propertyName) throws PropertyException
Range
validateMinMaxValues
in interface Range<Integer>
propertyName
- the name of the property.PropertyException
- if minValue is greather than maxValue.PropertyType.validateConstraints(String)
public Integer getMaxValue()
getMaxValue
in interface Range<Integer>
public Integer getMinValue()
getMinValue
in interface Range<Integer>
public void setMinValue(Integer minValue)
setMinValue
in interface Range<Integer>
minValue
- the min value.public void setMaxValue(Integer maxValue)
setMaxValue
in interface Range<Integer>
maxValue
- the max value.public boolean isUseMinValue()
isUseMinValue
in interface Range<Integer>
true
if min value is not null
, otherwise false
.public boolean isUseMaxValue()
isUseMaxValue
in interface Range<Integer>
true
if max value is not null
, otherwise false
.