org.apache.commons.lang3.time

## Class FastDateParser

- java.lang.Object
- - org.apache.commons.lang3.time.FastDateParser

- All Implemented Interfaces:
    Serializable, DateParser

      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 has 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.

  Since:
    3.2
  Version:
    $Id: FastDateParser.java 1572877 2014-02-28 08:42:25Z britter $
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `FastDateParser(String pattern, TimeZone timeZone, Locale locale)` Constructs a new FastDateParser.
    `protected` | `FastDateParser(String pattern, TimeZone timeZone, Locale locale, Date centuryStart)` Constructs a new FastDateParser.

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### FastDateParser

          protected FastDateParser(String pattern,
                        TimeZone timeZone,
                        Locale locale)

      Constructs a new FastDateParser.

      Parameters:
        `pattern` - non-null `SimpleDateFormat` compatible pattern
        `timeZone` - non-null time zone to use
        `locale` - non-null locale

    - #### FastDateParser

          protected FastDateParser(String pattern,
                        TimeZone timeZone,
                        Locale locale,
                        Date centuryStart)

      Constructs a new FastDateParser.

      Parameters:
        `pattern` - non-null `SimpleDateFormat` compatible pattern
        `timeZone` - non-null time zone to use
        `locale` - non-null locale
        `centuryStart` - The start of the century for 2 digit year parsing
      Since:
        3.3

  - ### Method Detail

    - #### getPattern

          public String getPattern()

      Description copied from interface: `DateParser`

      Get the pattern used by this parser.

      Specified by:
        `getPattern` in interface `DateParser`
      Returns:
        the pattern, `SimpleDateFormat` compatible

    - #### getTimeZone

          public TimeZone getTimeZone()

      Description copied from interface: `DateParser`

      Get 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.

      Specified by:
        `getTimeZone` in interface `DateParser`
      Returns:
        the time zone

    - #### getLocale

          public Locale getLocale()

      Description copied from interface: `DateParser`

      Get the locale used by this parser.

      Specified by:
        `getLocale` in interface `DateParser`
      Returns:
        the locale

    - #### equals

          public boolean equals(Object obj)

      Compare another object for equality with this object.

      Overrides:
        `equals` in class `Object`
      Parameters:
        `obj` - the object to compare to
      Returns:
        `true`if equal to this instance

    - #### hashCode

          public int hashCode()

      Return a hashcode compatible with equals.

      Overrides:
        `hashCode` in class `Object`
      Returns:
        a hashcode compatible with equals

    - #### toString

          public String toString()

      Get a string version of this formatter.

      Overrides:
        `toString` in class `Object`
      Returns:
        a debugging string

    - #### parseObject

          public Object parseObject(String source)
                             throws ParseException

      Description copied from interface: `DateParser`
      Parses text from a string to produce a Date.
      Specified by:
        `parseObject` in interface `DateParser`
      Parameters:
        `source` - A `String` whose beginning should be parsed.
      Returns:
        a `java.util.Date` object
      Throws:
        `ParseException` - if the beginning of the specified string cannot be parsed.
      See Also:
        `Format.parseObject(String)`

    - #### parse

          public Date parse(String source)
                     throws ParseException

      Description copied from interface: `DateParser`
      Equivalent to DateFormat.parse(String). See `DateFormat.parse(String)` for more information.
      Specified by:
        `parse` in interface `DateParser`
      Parameters:
        `source` - A `String` whose beginning should be parsed.
      Returns:
        A `Date` parsed from the string
      Throws:
        `ParseException` - if the beginning of the specified string cannot be parsed.

    - #### parseObject

          public Object parseObject(String source,
                           ParsePosition pos)

      Description copied from interface: `DateParser`
      Parse a date/time string according to the given parse position.
      Specified by:
        `parseObject` in interface `DateParser`
      Parameters:
        `source` - A `String` whose beginning should be parsed.
        `pos` - the parse position
      Returns:
        a `java.util.Date` object
      See Also:
        `DateFormat.parseObject(String, ParsePosition)`

    - #### parse

          public Date parse(String source,
                   ParsePosition pos)

      Description copied from interface: `DateParser`
      Equivalent to DateFormat.parse(String, ParsePosition). See `DateFormat.parse(String, ParsePosition)` for more information.
      Specified by:
        `parse` in interface `DateParser`
      Parameters:
        `source` - A `String`, part of which should be parsed.
        `pos` - A `ParsePosition` object with index and error index information as described above.
      Returns:
        A `Date` parsed from the string. In case of error, returns null.

Copyright © 2001–2014 The Apache Software Foundation. All rights reserved.