public class FastDateParser extends Object implements DateParser, Serializable
FastDateParser is a fast and thread-safe version of
SimpleDateFormat.
This class can be used as a direct replacement for
SimpleDateFormat in most parsing situations.
This class is especially useful in multi-threaded server environments.
SimpleDateFormat is not thread-safe in any JDK version,
nor will it be as Sun have closed the
bug/RFE.
Only parsing is supported, but all patterns are compatible with SimpleDateFormat.
Timing tests indicate this class is as about as fast as SimpleDateFormat in single thread applications and about 25% faster in multi-thread applications.
Note that the code only handles Gregorian calendars. The following non-Gregorian calendars use SimpleDateFormat internally, and so will be slower:
| Modifier | Constructor and Description |
|---|---|
protected |
FastDateParser(String pattern,
TimeZone timeZone,
Locale locale)
Constructs a new FastDateParser.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Compare another object for equality with this object.
|
Locale |
getLocale()
Get the locale used by this parser.
|
String |
getPattern()
Get the pattern used by this parser.
|
TimeZone |
getTimeZone()
Get the time zone used by this parser.
|
int |
hashCode()
Return a hashcode compatible with equals.
|
Date |
parse(String source)
Equivalent to DateFormat.parse(String).
|
Date |
parse(String source,
ParsePosition pos)
Equivalent to DateFormat.parse(String, ParsePosition).
|
Object |
parseObject(String source)
Parses text from a string to produce a Date.
|
Object |
parseObject(String source,
ParsePosition pos)
Parse a date/time string according to the given parse position.
|
String |
toString()
Get a string version of this formatter.
|
protected FastDateParser(String pattern, TimeZone timeZone, Locale locale)
Constructs a new FastDateParser.
pattern - non-null SimpleDateFormat compatible
patterntimeZone - non-null time zone to uselocale - non-null localepublic String getPattern()
DateParserGet the pattern used by this parser.
getPattern in interface DateParserSimpleDateFormat compatiblepublic TimeZone getTimeZone()
DateParserGet the time zone used by this parser.
The default TimeZone used to create a Date when the TimeZone is not specified by
the format pattern.
getTimeZone in interface DateParserpublic Locale getLocale()
DateParserGet the locale used by this parser.
getLocale in interface DateParserpublic int hashCode()
Return a hashcode compatible with equals.
public Object parseObject(String source) throws ParseException
DateParserparseObject in interface DateParsersource - A String whose beginning should be parsed.java.util.Date objectParseException - if the beginning of the specified string cannot be parsed.Format.parseObject(String)public Date parse(String source) throws ParseException
DateParserDateFormat.parse(String) for more information.parse in interface DateParsersource - A String whose beginning should be parsed.Date parsed from the stringParseException - if the beginning of the specified string cannot be parsed.public Object parseObject(String source, ParsePosition pos)
DateParserparseObject in interface DateParsersource - A String whose beginning should be parsed.pos - the parse positionjava.util.Date objectDateFormat.parseObject(String, ParsePosition)public Date parse(String source, ParsePosition pos)
DateParserDateFormat.parse(String, ParsePosition) for more information.parse in interface DateParsersource - A String, part of which should be parsed.pos - A ParsePosition object with index and error index information
as described above.Date parsed from the string. In case of error, returns null.Copyright © 2001–2014 The Apache Software Foundation. All rights reserved.