Package org.alfresco.util
Class CachingDateFormat
- java.lang.Object
-
- java.text.Format
-
- java.text.DateFormat
-
- java.text.SimpleDateFormat
-
- org.alfresco.util.CachingDateFormat
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class CachingDateFormat extends java.text.SimpleDateFormat
Provides thread safe means of obtaining a cached date formatter.The cached string-date mappings are stored in a WeakHashMap.
- Author:
- Derek Hulley
- See Also:
DateFormat.setLenient(boolean)
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CachingDateFormat.SimpleDateFormatAndResolution
static class
CachingDateFormat.StringAndResolution
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FORMAT_CMIS_SQL
yyyy-MM-dd'T'HH:mm:ssstatic java.lang.String
FORMAT_DATE_GENERIC
yyyy-MM-ddstatic java.lang.String
FORMAT_FULL_GENERIC
yyyy-MM-dd'T'HH:mm:ssstatic java.lang.String
FORMAT_SOLR
static java.lang.String
FORMAT_TIME_GENERIC
HH:mm:ssstatic CachingDateFormat.StringAndResolution[]
LENIENT_FORMATS
-
Fields inherited from class java.text.DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.text.SimpleDateFormat
getCmisSqlDatetimeFormat()
static java.text.SimpleDateFormat
getDateFormat()
static java.text.SimpleDateFormat
getDateFormat(int length, java.util.Locale locale, boolean lenient)
static java.text.SimpleDateFormat
getDateFormat(java.lang.String pattern, boolean lenient)
static java.text.SimpleDateFormat
getDateOnlyFormat()
static java.text.SimpleDateFormat
getDateTimeFormat(int dateLength, int timeLength, java.util.Locale locale, boolean lenient)
static CachingDateFormat.SimpleDateFormatAndResolution[]
getLenientFormatters()
static java.text.SimpleDateFormat
getSolrDatetimeFormat()
static java.text.SimpleDateFormat
getTimeOnlyFormat()
static Pair<java.util.Date,java.lang.Integer>
lenientParse(java.lang.String text, int minimumResolution)
java.util.Date
parse(java.lang.String text, java.text.ParsePosition pos)
Parses and caches date strings.java.lang.String
toString()
-
Methods inherited from class java.text.SimpleDateFormat
applyLocalizedPattern, applyPattern, clone, equals, format, formatToCharacterIterator, get2DigitYearStart, getDateFormatSymbols, hashCode, set2DigitYearStart, setDateFormatSymbols, toLocalizedPattern, toPattern
-
Methods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
-
-
-
-
Field Detail
-
FORMAT_FULL_GENERIC
public static final java.lang.String FORMAT_FULL_GENERIC
yyyy-MM-dd'T'HH:mm:ss
- See Also:
- Constant Field Values
-
FORMAT_CMIS_SQL
public static final java.lang.String FORMAT_CMIS_SQL
yyyy-MM-dd'T'HH:mm:ss
- See Also:
- Constant Field Values
-
FORMAT_SOLR
public static final java.lang.String FORMAT_SOLR
- See Also:
- Constant Field Values
-
LENIENT_FORMATS
public static final CachingDateFormat.StringAndResolution[] LENIENT_FORMATS
-
FORMAT_DATE_GENERIC
public static final java.lang.String FORMAT_DATE_GENERIC
yyyy-MM-dd
- See Also:
- Constant Field Values
-
FORMAT_TIME_GENERIC
public static final java.lang.String FORMAT_TIME_GENERIC
HH:mm:ss
- See Also:
- Constant Field Values
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDateFormat
public static java.text.SimpleDateFormat getDateFormat(int length, java.util.Locale locale, boolean lenient)
- Parameters:
length
- the type of date format, e.g.DateFormat.LONG
locale
- theLocale
that will be used to determine the date pattern- See Also:
getDateFormat(String, boolean)
,DateFormat.SHORT
,DateFormat.MEDIUM
,DateFormat.LONG
,DateFormat.FULL
-
getDateTimeFormat
public static java.text.SimpleDateFormat getDateTimeFormat(int dateLength, int timeLength, java.util.Locale locale, boolean lenient)
- Parameters:
dateLength
- the type of date format, e.g.DateFormat.LONG
timeLength
- the type of time format, e.g.DateFormat.LONG
locale
- theLocale
that will be used to determine the date pattern- See Also:
getDateFormat(String, boolean)
,DateFormat.SHORT
,DateFormat.MEDIUM
,DateFormat.LONG
,DateFormat.FULL
-
getDateFormat
public static java.text.SimpleDateFormat getDateFormat(java.lang.String pattern, boolean lenient)
- Parameters:
pattern
- the conversion pattern to uselenient
- true to allow the parser to extract the date in conceivable manner- Returns:
- Returns a conversion-cacheing formatter for the given pattern, but the instance itself is not cached
-
getDateFormat
public static java.text.SimpleDateFormat getDateFormat()
- Returns:
- Returns a thread-safe formatter for the generic date/time format
- See Also:
FORMAT_FULL_GENERIC
-
getCmisSqlDatetimeFormat
public static java.text.SimpleDateFormat getCmisSqlDatetimeFormat()
- Returns:
- Returns a thread-safe formatter for the cmis sql datetime format
-
getSolrDatetimeFormat
public static java.text.SimpleDateFormat getSolrDatetimeFormat()
- Returns:
- Returns a thread-safe formatter for the cmis sql datetime format
-
getDateOnlyFormat
public static java.text.SimpleDateFormat getDateOnlyFormat()
- Returns:
- Returns a thread-safe formatter for the generic date format
- See Also:
FORMAT_DATE_GENERIC
-
getTimeOnlyFormat
public static java.text.SimpleDateFormat getTimeOnlyFormat()
- Returns:
- Returns a thread-safe formatter for the generic time format
- See Also:
FORMAT_TIME_GENERIC
-
parse
public java.util.Date parse(java.lang.String text, java.text.ParsePosition pos)
Parses and caches date strings.- Overrides:
parse
in classjava.text.SimpleDateFormat
- See Also:
DateFormat.parse(java.lang.String, java.text.ParsePosition)
-
lenientParse
public static Pair<java.util.Date,java.lang.Integer> lenientParse(java.lang.String text, int minimumResolution) throws java.text.ParseException
- Throws:
java.text.ParseException
-
getLenientFormatters
public static CachingDateFormat.SimpleDateFormatAndResolution[] getLenientFormatters()
-
-