public class ByteSizePropertyType extends PropertyType<ByteSizeVO> implements Range<ByteSizeVO>
dk.heick.properties.types.custom.ByteSizeVO
. number unit
. Constructor Example | Comments | ||
---|---|---|---|
Property<ByteSizeVO> A_PROPERTY = |
No default value, no mininum or maximum value. | ||
Property<ByteSizeVO> A_PROPERTY = |
With default value of "3 KB", no mininum or maximum value. | ||
Property<ByteSizeVO> A_PROPERTY = |
With default value of "5 MB", and mininum value of "512 KB" and maximum value "10 MB" Both inclusive. | ||
Type of value(s) | Examples | Result | Comments |
Valid | 4 mb | new ByteSizeVO(4,ByteSizeUnit.MB) |
Validate successfully. |
Valid | 64 kB | new ByteSizeVO(64,ByteSizeUnit.KB) |
Validate successfully. |
Valid | 1.342 b | new ByteSizeVO(1.342,ByteSizeUnit.B) |
Validate successfully. |
Valid | 3.2 GB | new ByteSizeVO(3.2,ByteSizeUnit.GB) |
Validate successfully. |
Invalid | cow | null |
Validate will throw an exception. The resulting value is null . |
Invalid | «empty string» | null |
Validate will throw an exception. The resulting value is null . |
Invalid | «empty string after trim» | null |
Validate will throw an exception. The resulting value is null . |
Invalid | null |
defaultValue OR null |
Validate will throw an exception. Return default value if set, otherwise null . |
ByteSizeVO
,
ByteSizeUnit
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
TYPE
The type name string constant of ByteSizePropertyType.
|
Constructor and Description |
---|
ByteSizePropertyType()
Default constructor, no default value and no minimum or maximum value constraints.
|
ByteSizePropertyType(ByteSizeVO defaultValue)
Constructor with default value, but no minimum or maximum value constraints.
|
ByteSizePropertyType(ByteSizeVO minValue,
ByteSizeVO maxValue) |
ByteSizePropertyType(ByteSizeVO defaultValue,
ByteSizeVO minValue,
ByteSizeVO maxValue)
Constructor with minimum, maximum and default value.
|
Modifier and Type | Method and Description |
---|---|
ByteSizeVO |
getMaxValue()
The maximum value (inclusive)
|
ByteSizeVO |
getMinValue()
The minimum value (inclusive)
|
List<String> |
getRestrictions()
Gets a detailed description of the PropertyType with any constraints that might influence the validation.
|
boolean |
isUseMaxValue()
If there is a maximum limit.
|
boolean |
isUseMinValue()
If there is a minimum limit.
|
protected double |
parseNumberPart(String propertyName,
String value,
String numberPart) |
protected ByteSizeUnit |
parseUnitPart(String propertyName,
String value,
String unitPart) |
void |
setMaxValue(ByteSizeVO maxValue)
Sets the maximum limit (inclusive).
|
void |
setMinValue(ByteSizeVO minValue)
Sets the minimum limit (inclusive).
|
void |
validateConstraints(String propertyName)
A PropertyType can have some constraints here is where they are
validated.
|
void |
validateIsInRange(String propertyName,
ByteSizeVO 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.
|
ByteSizeVO |
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 ByteSizePropertyType()
public ByteSizePropertyType(ByteSizeVO defaultValue)
defaultValue
- default value returned if property value is undefined.public ByteSizePropertyType(ByteSizeVO minValue, ByteSizeVO maxValue)
public ByteSizePropertyType(ByteSizeVO defaultValue, ByteSizeVO minValue, ByteSizeVO maxValue)
defaultValue
- default value returned if property value is undefined.minValue
- minimum value, inclusive.maxValue
- maximum value, inclusive.public List<String> getRestrictions()
PropertyType
getRestrictions
in class PropertyType<ByteSizeVO>
public ByteSizeVO getMinValue()
Range
getMinValue
in interface Range<ByteSizeVO>
null
than no minimum limit.public ByteSizeVO getMaxValue()
Range
getMaxValue
in interface Range<ByteSizeVO>
null
than no minimum limit.public void setMinValue(ByteSizeVO minValue)
Range
setMinValue
in interface Range<ByteSizeVO>
minValue
- the minimum limit, if null
than no limit.public void setMaxValue(ByteSizeVO maxValue)
Range
setMaxValue
in interface Range<ByteSizeVO>
maxValue
- the maximum limit, if null
than no limit.public boolean isUseMaxValue()
Range
isUseMaxValue
in interface Range<ByteSizeVO>
true
if getMaxValue() differs from null
, otherwise false
.public boolean isUseMinValue()
Range
isUseMinValue
in interface Range<ByteSizeVO>
true
if getMinValue() differs from null
, otherwise false
.public ByteSizeVO validateValue(String propertyName, String value) throws PropertyException
PropertyType
validateValue
in class PropertyType<ByteSizeVO>
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.protected double parseNumberPart(String propertyName, String value, String numberPart) throws PropertyException
PropertyException
protected ByteSizeUnit parseUnitPart(String propertyName, String value, String unitPart) throws PropertyException
PropertyException
public void validateConstraints(String propertyName) throws PropertyException
PropertyType
validateConstraints
in class PropertyType<ByteSizeVO>
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, ByteSizeVO value) throws PropertyException
Range
validateIsInRange
in interface Range<ByteSizeVO>
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<ByteSizeVO>
propertyName
- the name of the property.PropertyException
- if minValue is greather than maxValue.PropertyType.validateConstraints(String)