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:
Serializable,Cloneable
public class CachingDateFormat extends SimpleDateFormat
Provides thread safe means of obtaining a cached date formatter.The cached string-date mappings are stored in a WeakHashMap.
- Author:
- Derek Hulley, Andrea Gazzarini
- See Also:
DateFormat.setLenient(boolean), Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCachingDateFormat.SimpleDateFormatAndResolutionstatic classCachingDateFormat.StringAndResolution-
Nested classes/interfaces inherited from class java.text.DateFormat
DateFormat.Field
-
-
Field Summary
Fields Modifier and Type Field Description static StringFORMAT_CMIS_SQLstatic StringFORMAT_DATE_GENERICstatic StringFORMAT_FULL_GENERICstatic StringFORMAT_SOLRstatic StringFORMAT_TIME_GENERICstatic CachingDateFormat.StringAndResolution[]LENIENT_FORMATSstatic StringUTCstatic StringUTC_WITHOUT_MSECS-
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 SimpleDateFormatgetCmisSqlDatetimeFormat()Returns a thread-safe formatter for the cmis sql datetime format.static SimpleDateFormatgetDateFormat()Returns a thread-safe formatter for the generic date/time format.static SimpleDateFormatgetDateFormat(int length, Locale locale, boolean lenient)static SimpleDateFormatgetDateFormat(String pattern, boolean lenient)static SimpleDateFormatgetDateOnlyFormat()static SimpleDateFormatgetDateTimeFormat(int dateLength, int timeLength, Locale locale, boolean lenient)static CachingDateFormat.SimpleDateFormatAndResolution[]getLenientFormatters()static SimpleDateFormatgetSolrDatetimeFormat()Returns a thread-safe formatter for the Solr ISO 8601 datetime format.static SimpleDateFormatgetSolrDatetimeFormatWithoutMsecs()Returns a thread-safe formatter for the Solr ISO 8601 datetime format (without the msecs part).static SimpleDateFormatgetTimeOnlyFormat()Returns a thread-safe formatter for the generic time format.static Pair<Date,Integer>lenientParse(String text, int minimumResolution)Dateparse(String text, ParsePosition pos)Parses and caches date strings.StringtoString()-
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
-
Methods inherited from class java.text.Format
format, parseObject
-
-
-
-
Field Detail
-
UTC
public static final String UTC
- See Also:
- Constant Field Values
-
FORMAT_FULL_GENERIC
public static final String FORMAT_FULL_GENERIC
- See Also:
- Constant Field Values
-
FORMAT_CMIS_SQL
public static final String FORMAT_CMIS_SQL
- See Also:
- Constant Field Values
-
FORMAT_SOLR
public static final String FORMAT_SOLR
- See Also:
- Constant Field Values
-
UTC_WITHOUT_MSECS
public static final String UTC_WITHOUT_MSECS
- See Also:
- Constant Field Values
-
FORMAT_DATE_GENERIC
public static final String FORMAT_DATE_GENERIC
- See Also:
- Constant Field Values
-
FORMAT_TIME_GENERIC
public static final String FORMAT_TIME_GENERIC
- See Also:
- Constant Field Values
-
LENIENT_FORMATS
public static final CachingDateFormat.StringAndResolution[] LENIENT_FORMATS
-
-
Method Detail
-
getDateFormat
public static SimpleDateFormat getDateFormat(int length, Locale locale, boolean lenient)
- Parameters:
length- the type of date format, e.g.DateFormat.LONGlocale- theLocalethat will be used to determine the date pattern- See Also:
getDateFormat(String, boolean),DateFormat.SHORT,DateFormat.MEDIUM,DateFormat.LONG,DateFormat.FULL
-
getDateTimeFormat
public static SimpleDateFormat getDateTimeFormat(int dateLength, int timeLength, Locale locale, boolean lenient)
- Parameters:
dateLength- the type of date format, e.g.DateFormat.LONGtimeLength- the type of time format, e.g.DateFormat.LONGlocale- theLocalethat will be used to determine the date pattern- See Also:
getDateFormat(String, boolean),DateFormat.SHORT,DateFormat.MEDIUM,DateFormat.LONG,DateFormat.FULL
-
getDateFormat
public static SimpleDateFormat getDateFormat(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 SimpleDateFormat getDateFormat()
Returns a thread-safe formatter for the generic date/time format.- Returns:
- a thread-safe formatter for the generic date/time format.
- See Also:
FORMAT_FULL_GENERIC
-
getCmisSqlDatetimeFormat
public static SimpleDateFormat getCmisSqlDatetimeFormat()
Returns a thread-safe formatter for the cmis sql datetime format.- Returns:
- a thread-safe formatter for the cmis sql datetime format.
- See Also:
FORMAT_CMIS_SQL
-
getSolrDatetimeFormatWithoutMsecs
public static SimpleDateFormat getSolrDatetimeFormatWithoutMsecs()
Returns a thread-safe formatter for the Solr ISO 8601 datetime format (without the msecs part).- Returns:
- Returns a thread-safe formatter for the Solr ISO 8601 datetime format (without the msecs part).
- See Also:
UTC_WITHOUT_MSECS
-
getSolrDatetimeFormat
public static SimpleDateFormat getSolrDatetimeFormat()
Returns a thread-safe formatter for the Solr ISO 8601 datetime format.- Returns:
- a thread-safe formatter for the Solr ISO 8601 datetime format
- See Also:
FORMAT_SOLR
-
getDateOnlyFormat
public static SimpleDateFormat getDateOnlyFormat()
- Returns:
- Returns a thread-safe formatter for the generic date format
- See Also:
FORMAT_DATE_GENERIC
-
getTimeOnlyFormat
public static SimpleDateFormat getTimeOnlyFormat()
Returns a thread-safe formatter for the generic time format.- Returns:
- a thread-safe formatter for the generic time format.
- See Also:
FORMAT_TIME_GENERIC
-
parse
public Date parse(String text, ParsePosition pos)
Parses and caches date strings.- Overrides:
parsein classSimpleDateFormat- See Also:
DateFormat.parse(java.lang.String, java.text.ParsePosition)
-
lenientParse
public static Pair<Date,Integer> lenientParse(String text, int minimumResolution) throws ParseException
- Throws:
ParseException
-
getLenientFormatters
public static CachingDateFormat.SimpleDateFormatAndResolution[] getLenientFormatters()
-
-