Enum DateType
- java.lang.Object
-
- java.lang.Enum<DateType>
-
- org.simpleframework.xml.transform.DateType
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<DateType>
enum DateType extends java.lang.Enum<DateType>
TheDateType
enumeration provides a set of known date formats supported by the date transformer. This allows the XML representation of a date to come in several formats, from most accurate to least. Enumerating the dates ensures that resolution of the format is fast by enabling inspection of the date string.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DateType.DateFormat
TheDateFormat
provides a synchronized means for using the simple date format object.
-
Enum Constant Summary
Enum Constants Enum Constant Description FULL
This is the default date format used by the date transform.LONG
This is the date type without millisecond resolution.NORMAL
This date type enables only the specific date to be used.SHORT
This is the shortest format that relies on the date locale.
-
Field Summary
Fields Modifier and Type Field Description private DateType.DateFormat
format
This is the date formatter that is used to parse the date.
-
Constructor Summary
Constructors Modifier Constructor Description private
DateType(java.lang.String format)
Constructor for theDateType
enumeration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.Date
getDate(java.lang.String text)
This is used to convert the string to a date value.private DateType.DateFormat
getFormat()
Acquires the date format from the date type.static java.lang.String
getText(java.util.Date date)
This is used to convert the date to a string value.static DateType
getType(java.lang.String text)
This is used to acquire a date type using the specified text as input.static DateType
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static DateType[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
FULL
public static final DateType FULL
This is the default date format used by the date transform.
-
LONG
public static final DateType LONG
This is the date type without millisecond resolution.
-
NORMAL
public static final DateType NORMAL
This date type enables only the specific date to be used.
-
SHORT
public static final DateType SHORT
This is the shortest format that relies on the date locale.
-
-
Field Detail
-
format
private DateType.DateFormat format
This is the date formatter that is used to parse the date.
-
-
Method Detail
-
values
public static DateType[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DateType c : DateType.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DateType valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
getFormat
private DateType.DateFormat getFormat()
Acquires the date format from the date type. This is then used to parse the date string and convert it to a usable date. The format returned is synchronized for safety.- Returns:
- this returns the date format to be used
-
getText
public static java.lang.String getText(java.util.Date date) throws java.lang.Exception
This is used to convert the date to a string value. The string value can then be embedded in to the generated XML in such a way that it can be recovered as aDate
when the value is transformed by the date transform.- Parameters:
date
- this is the date that is converted to a string- Returns:
- this returns the string to represent the date
- Throws:
java.lang.Exception
-
getDate
public static java.util.Date getDate(java.lang.String text) throws java.lang.Exception
This is used to convert the string to a date value. The date value can then be recovered from the generated XML by parsing the text with one of the known date formats. This allows bidirectional transformation of dates to strings.- Parameters:
text
- this is the date that is converted to a date- Returns:
- this returns the date parsed from the string value
- Throws:
java.lang.Exception
-
getType
public static DateType getType(java.lang.String text)
This is used to acquire a date type using the specified text as input. This will perform some checks on the raw string to match it to the appropriate date type. Resolving the date type in this way ensures that only one date type needs to be used.- Parameters:
text
- this is the text to be matched with a date type- Returns:
- the most appropriate date type for the given string
-
-