Class FastDateParser
- java.lang.Object
-
- org.apache.commons.lang3.time.FastDateParser
-
- All Implemented Interfaces:
- java.io.Serializable, DateParser
public class FastDateParser extends java.lang.Object implements DateParser, java.io.Serializable
FastDateParser is a fast and thread-safe version of
SimpleDateFormat.This class can be used as a direct replacement for
SimpleDateFormatin most parsing situations. This class is especially useful in multi-threaded server environments.SimpleDateFormatis 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:
- ja_JP_TH - Japanese Imperial
- th_TH (any variant) - Thai Buddhist
- Since:
- 3.2
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanequals(java.lang.Object obj)Compare another object for equality with this object.java.util.LocalegetLocale()Get the locale used by this parser.java.lang.StringgetPattern()Get the pattern used by this parser.java.util.TimeZonegetTimeZone()Get the time zone used by this parser.inthashCode()Return a hashcode compatible with equals.java.util.Dateparse(java.lang.String source)Equivalent to DateFormat.parse(String).java.util.Dateparse(java.lang.String source, java.text.ParsePosition pos)Equivalent to DateFormat.parse(String, ParsePosition).java.lang.ObjectparseObject(java.lang.String source)Parses text from a string to produce a Date.java.lang.ObjectparseObject(java.lang.String source, java.text.ParsePosition pos)Parse a date/time string according to the given parse position.java.lang.StringtoString()Get a string version of this formatter.
-
-
-
Method Detail
-
getPattern
public java.lang.String getPattern()
Description copied from interface:DateParserGet the pattern used by this parser.
- Specified by:
getPatternin interfaceDateParser- Returns:
- the pattern,
SimpleDateFormatcompatible
-
getTimeZone
public java.util.TimeZone getTimeZone()
Description copied from interface:DateParserGet the time zone used by this parser.
The default
TimeZoneused to create aDatewhen theTimeZoneis not specified by the format pattern.- Specified by:
getTimeZonein interfaceDateParser- Returns:
- the time zone
-
getLocale
public java.util.Locale getLocale()
Description copied from interface:DateParserGet the locale used by this parser.
- Specified by:
getLocalein interfaceDateParser- Returns:
- the locale
-
equals
public boolean equals(java.lang.Object obj)
Compare another object for equality with this object.
- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare to- Returns:
trueif equal to this instance
-
hashCode
public int hashCode()
Return a hashcode compatible with equals.
- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hashcode compatible with equals
-
toString
public java.lang.String toString()
Get a string version of this formatter.
- Overrides:
toStringin classjava.lang.Object- Returns:
- a debugging string
-
parseObject
public java.lang.Object parseObject(java.lang.String source) throws java.text.ParseExceptionDescription copied from interface:DateParserParses text from a string to produce a Date.- Specified by:
parseObjectin interfaceDateParser- Parameters:
source- AStringwhose beginning should be parsed.- Returns:
- a
java.util.Dateobject - Throws:
java.text.ParseException- if the beginning of the specified string cannot be parsed.- See Also:
Format.parseObject(String)
-
parse
public java.util.Date parse(java.lang.String source) throws java.text.ParseExceptionDescription copied from interface:DateParserEquivalent to DateFormat.parse(String). SeeDateFormat.parse(String)for more information.- Specified by:
parsein interfaceDateParser- Parameters:
source- AStringwhose beginning should be parsed.- Returns:
- A
Dateparsed from the string - Throws:
java.text.ParseException- if the beginning of the specified string cannot be parsed.
-
parseObject
public java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)Description copied from interface:DateParserParse a date/time string according to the given parse position.- Specified by:
parseObjectin interfaceDateParser- Parameters:
source- AStringwhose beginning should be parsed.pos- the parse position- Returns:
- a
java.util.Dateobject - See Also:
DateFormat.parseObject(String, ParsePosition)
-
parse
public java.util.Date parse(java.lang.String source, java.text.ParsePosition pos)Description copied from interface:DateParserEquivalent to DateFormat.parse(String, ParsePosition). SeeDateFormat.parse(String, ParsePosition)for more information.- Specified by:
parsein interfaceDateParser- Parameters:
source- AString, part of which should be parsed.pos- AParsePositionobject with index and error index information as described above.- Returns:
- A
Dateparsed from the string. In case of error, returns null.
-
-
DMelt 3.0 © DataMelt by jWork.ORG