public class TimeSpanPropertyType extends PropertyType<TimeSpan> implements Range<TimeSpan>
dk.heick.properties.types.custom.TimeSpan
value. dk.heick.properties.types.custom.TimeSpan
. Constructor Example | Comments | ||
---|---|---|---|
Property<Timespan> A_PROPERTY = |
Creates TimespanPropertyType with no default value. | ||
Property<Timespan> A_PROPERTY = |
Creates TimespanPropertyType with default value "TimeSpan.DAYS_21". | ||
Type of value(s) | Examples | Result | Comments |
Valid | 41y 84d 4h 48m 3s | new TimeSpan(41,0,0,84,4,48,3,0) | Validate successfully. |
Invalid | cow | null |
Validate will throw an exception. The resulting value is 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 . |
TimeSpan
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
TYPE
The type name string constant of TimespanPropertyType.
|
Constructor and Description |
---|
TimeSpanPropertyType()
Constructor where the defaultValue, minValue and maxValue is
null . |
TimeSpanPropertyType(TimeSpan defaultValue)
Constructor where minValue and maxValue is
null . |
TimeSpanPropertyType(TimeSpan minValue,
TimeSpan maxValue)
Constructor where the default value is
null . |
TimeSpanPropertyType(TimeSpan defaultValue,
TimeSpan minValue,
TimeSpan maxValue)
Constructor
|
Modifier and Type | Method and Description |
---|---|
TimeSpan |
getMaxValue()
Gets the max value (inclusive) a value may be.
|
TimeSpan |
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(TimeSpan maxValue)
Sets the max value (inclusive) a value may be.
|
void |
setMinValue(TimeSpan minValue)
Sets the min value (inclusive) a value may be.
|
String |
toString(String propertyName,
TimeSpan t)
Returns a parseable Timespan text value.
|
void |
validateConstraints(String propertyName)
A PropertyType can have some constraints here is where they are
validated.
|
void |
validateIsInRange(String propertyName,
TimeSpan 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.
|
TimeSpan |
validateValue(String propertyName,
String value)
Parses the text using the
TimeSpan.parse(String) and if the result is inside valid min and max values. |
equals, getDefaultValue, getDefaultValueAsString, getDefaultValueDescription, getDescription, getDescription, getInitializationPriority, getIo, getLogger, getTypeName, hasDefaultValue, isDefaultValueValid, postGetValueProcessing, setDefaultValue, setInitializationPriority, setIo, setTypedValue, setTypeName, toType, validate, validateNullType
public static final String TYPE
public TimeSpanPropertyType()
null
.public TimeSpanPropertyType(TimeSpan defaultValue)
null
.defaultValue
- the default TimeSpan value.public TimeSpanPropertyType(TimeSpan minValue, TimeSpan maxValue)
null
.minValue
- the minimum Timespan value (inclusive), if null
than no minimum limit.maxValue
- the maximum Timespan value (inclusive), if null
than no maximum limit.public TimeSpanPropertyType(TimeSpan defaultValue, TimeSpan minValue, TimeSpan maxValue)
defaultValue
- the default TimeSpan value.minValue
- the minimum Timespan value (inclusive), if null
than no minimum limit.maxValue
- the maximum Timespan value (inclusive), if null
than no maximum limit.public TimeSpan getMaxValue()
getMaxValue
in interface Range<TimeSpan>
public TimeSpan getMinValue()
getMinValue
in interface Range<TimeSpan>
public void setMinValue(TimeSpan minValue)
setMinValue
in interface Range<TimeSpan>
minValue
- the min value.public void setMaxValue(TimeSpan maxValue)
setMaxValue
in interface Range<TimeSpan>
maxValue
- the max value.public boolean isUseMinValue()
isUseMinValue
in interface Range<TimeSpan>
true
if min value is not null
, otherwise false
.public boolean isUseMaxValue()
isUseMaxValue
in interface Range<TimeSpan>
true
if max value is not null
, otherwise false
.public List<String> getRestrictions()
PropertyType
getRestrictions
in class PropertyType<TimeSpan>
public TimeSpan validateValue(String propertyName, String value) throws PropertyException
TimeSpan.parse(String)
and if the result is inside valid min and max values.validateValue
in class PropertyType<TimeSpan>
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.TimeSpan.parse(String)
public String toString(String propertyName, TimeSpan t) throws PropertyException
toString
in class PropertyType<TimeSpan>
propertyName
- the name of the property used for logging purposes.t
- the type T.PropertyException
- if conversion failed in validation.TimeSpan.getParsableText()
public void validateConstraints(String propertyName) throws PropertyException
PropertyType
validateConstraints
in class PropertyType<TimeSpan>
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, TimeSpan value) throws PropertyException
Range
validateIsInRange
in interface Range<TimeSpan>
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<TimeSpan>
propertyName
- the name of the property.PropertyException
- if minValue is greather than maxValue.PropertyType.validateConstraints(String)