public class DateTimePropertyType extends PropertyType<Date> implements Range<Date>
java.util.Date. java.text.SimpleDateFormat for parse the string to a date by the pattern provided in constructor. | Constructor Example | Comments | ||
|---|---|---|---|
Property<Date> A_PROPERTY = |
Creates DateTimePropertyType with default SimpleDateFormat pattern "yyyy-MM-dd HH:mm:ss". No default value. | ||
Property<Date> A_PROPERTY = |
Creates DateTimePropertyType with default SimpleDateFormat pattern "dd/MM yyyy HH:mm:ss". No default value. | ||
Property<Date> A_PROPERTY = |
Creates DateTimePropertyType with default SimpleDateFormat pattern "HH:mm:ss". With default value "new Date(1234)". | ||
| Type of value(s) | Examples | Result | Comments |
| Valid | 1973-11-28 19:30:59 | new SimpleDateFormat("yyyy-MM-dd HH-mm-ss).format("1973-11-28 19:30:59") | 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. |
SimpleDateFormat,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_DATE_FORMAT
The default time pattern constant 'yyyyy-MM-dd'.
|
static String |
DEFAULT_DATETIME_FORMAT
The default date time pattern constant 'yyyy-MM-dd HH:mm:ss'.
|
static String |
DEFAULT_TIME_FORMAT
The default time pattern constant 'HH:mm:ss'.
|
static String |
TYPE
The type name string constant of DateTimePropertyType.
|
| Constructor and Description |
|---|
DateTimePropertyType()
Default constructor, initializes the with DEFAULT_DATETIME_FORMAT and
null as default value. |
DateTimePropertyType(Date defaultValue)
Constructor, initializes the with DEFAULT_DATETIME_FORMAT.
|
DateTimePropertyType(Date minValue,
Date maxValue)
Constructor, initializes the with DEFAULT_DATETIME_FORMAT and default value is
null. |
DateTimePropertyType(Date defaultValue,
Date minValue,
Date maxValue)
Constructor, initializes the with DEFAULT_DATETIME_FORMAT.
|
DateTimePropertyType(String dateFormatPattern)
Constructor with a dateFormatPattern which upholds the pattern rules for
SimpleDateFormat. |
DateTimePropertyType(String dateFormatPattern,
Date defaultValue)
Constructor with a dateFormatPattern which upholds the pattern rules for
SimpleDateFormat and a default value. |
DateTimePropertyType(String dateFormatPattern,
Date minValue,
Date maxValue)
Constructor with a dateFormatPattern which upholds the pattern rules for
SimpleDateFormat. |
DateTimePropertyType(String dateFormatPattern,
Date defaultValue,
Date minValue,
Date maxValue)
Constructor with a dateFormatPattern which upholds the pattern rules for
SimpleDateFormat and a default value. |
| Modifier and Type | Method and Description |
|---|---|
static DateTimePropertyType |
createDatetimeType()
Static factory which creates an instance with the default date time pattern.
|
static DateTimePropertyType |
createDatetimeType(Date defaultValue)
Static factory which creates an instance with the default date time pattern and a default Date if invalid property value.
|
static DateTimePropertyType |
createDateType()
Static factory which creates an instance with the default date pattern.
|
static DateTimePropertyType |
createDateType(Date defaultValue)
Static factory which creates an instance with the default date pattern and a default Date if invalid property value.
|
static DateTimePropertyType |
createTimeType()
Static factory which creates an instance with the default time pattern.
|
static DateTimePropertyType |
createTimeType(Date defaultValue)
Static factory which creates an instance with the default time pattern and a default Date if invalid property value.
|
String |
getDateFormatPattern()
The
SimpleDateFormat pattern which the DateTimePropertyType instance is initialized with. |
String |
getFormattedDate(Date date)
Format date using the type defined.
|
Date |
getMaxValue()
The maximum value (inclusive)
|
Date |
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.
|
void |
setDateFormatPattern(String dateFormatPattern)
Sets the pattern for
SimpleDateFormat and reinitialize the DateTimePropertyType with. |
void |
setMaxValue(Date maxValue)
Sets the maximum limit (inclusive).
|
void |
setMinValue(Date minValue)
Sets the minimum limit (inclusive).
|
String |
toString(String propertyName,
Date t)
Converts a typed to the string representation.
|
void |
validateConstraints(String propertyName)
A PropertyType can have some constraints here is where they are
validated.
|
void |
validateIsInRange(String propertyName,
Date 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.
|
Date |
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, toType, validate, validateNullTypepublic static final String TYPE
public static final String DEFAULT_DATETIME_FORMAT
SimpleDateFormat,
Constant Field Valuespublic static final String DEFAULT_DATE_FORMAT
SimpleDateFormat,
Constant Field Valuespublic static final String DEFAULT_TIME_FORMAT
SimpleDateFormat,
Constant Field Valuespublic DateTimePropertyType()
null as default value.DEFAULT_DATETIME_FORMATpublic DateTimePropertyType(Date defaultValue)
defaultValue - default value returned if property value is undefined.DEFAULT_DATETIME_FORMATpublic DateTimePropertyType(String dateFormatPattern)
SimpleDateFormat. null.dateFormatPattern - the patternSimpleDateFormatpublic DateTimePropertyType(String dateFormatPattern, Date defaultValue)
SimpleDateFormat and a default value.dateFormatPattern - the patterndefaultValue - default value returned if property value is undefined.public DateTimePropertyType(String dateFormatPattern, Date defaultValue, Date minValue, Date maxValue)
SimpleDateFormat and a default value.dateFormatPattern - the patterndefaultValue - default value returned if property value is undefined.minValue - the minimum value (Date) the value must have (inclusive), if null than no minimum limit.maxValue - the maximum value (Date) the value must have (inclusive), if null than no maximum limit.public DateTimePropertyType(Date defaultValue, Date minValue, Date maxValue)
defaultValue - default value returned if property value is undefined.minValue - the minimum value (Date) the value must have (inclusive), if null than no minimum limit.maxValue - the maximum value (Date) the value must have (inclusive), if null than no maximum limit.DEFAULT_DATETIME_FORMATpublic DateTimePropertyType(String dateFormatPattern, Date minValue, Date maxValue)
SimpleDateFormat. null.dateFormatPattern - the patternminValue - the minimum value (Date) the value must have (inclusive), if null than no minimum limit.maxValue - the maximum value (Date) the value must have (inclusive), if null than no maximum limit.SimpleDateFormatpublic DateTimePropertyType(Date minValue, Date maxValue)
null.minValue - the minimum value (Date) the value must have (inclusive), if null than no minimum limit.maxValue - the maximum value (Date) the value must have (inclusive), if null than no maximum limit.public static DateTimePropertyType createDatetimeType()
SimpleDateFormat,
DEFAULT_DATETIME_FORMATpublic static DateTimePropertyType createDateType()
SimpleDateFormat,
DEFAULT_DATE_FORMATpublic static DateTimePropertyType createTimeType()
SimpleDateFormat,
DEFAULT_TIME_FORMATpublic static DateTimePropertyType createDatetimeType(Date defaultValue)
defaultValue - default value returned if property value is undefined.SimpleDateFormat,
DEFAULT_DATETIME_FORMATpublic static DateTimePropertyType createDateType(Date defaultValue)
defaultValue - default value returned if property value is undefined.SimpleDateFormat,
DEFAULT_DATE_FORMATpublic static DateTimePropertyType createTimeType(Date defaultValue)
defaultValue - default value returned if property value is undefined.SimpleDateFormat,
DEFAULT_TIME_FORMATpublic String getDateFormatPattern()
SimpleDateFormat pattern which the DateTimePropertyType instance is initialized with.public void setDateFormatPattern(String dateFormatPattern)
SimpleDateFormat and reinitialize the DateTimePropertyType with.dateFormatPattern - the patternpublic String toString(String propertyName, Date t) throws PropertyException
PropertyTypetoString in class PropertyType<Date>propertyName - the name of the property used for logging purposes.t - the type T.PropertyException - if conversion failed in validation.PropertyType.validate(String, String)public Date validateValue(String propertyName, String value) throws PropertyException
PropertyTypevalidateValue in class PropertyType<Date>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
PropertyTypevalidateConstraints in class PropertyType<Date>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 final String getFormattedDate(Date date)
date - a date to format.public List<String> getRestrictions()
PropertyTypegetRestrictions in class PropertyType<Date>public void setMinValue(Date minValue)
RangesetMinValue in interface Range<Date>minValue - the minimum limit, if null than no limit.public void setMaxValue(Date maxValue)
RangesetMaxValue in interface Range<Date>maxValue - the maximum limit, if null than no limit.public Date getMinValue()
RangegetMinValue in interface Range<Date>null than no minimum limit.public Date getMaxValue()
RangegetMaxValue in interface Range<Date>null than no minimum limit.public boolean isUseMinValue()
RangeisUseMinValue in interface Range<Date>true if getMinValue() differs from null, otherwise false.public boolean isUseMaxValue()
RangeisUseMaxValue in interface Range<Date>true if getMaxValue() differs from null, otherwise false.public void validateIsInRange(String propertyName, Date value) throws PropertyException
RangevalidateIsInRange in interface Range<Date>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
RangevalidateMinMaxValues in interface Range<Date>propertyName - the name of the property.PropertyException - if minValue is greather than maxValue.PropertyType.validateConstraints(String)