Coverage Report - org.apache.commons.lang3.time.FastDateFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
FastDateFormat
86%
39/45
100%
2/2
1,053
FastDateFormat$1
100%
2/2
N/A
1,053
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.lang3.time;
 18  
 
 19  
 import java.text.DateFormat;
 20  
 import java.text.FieldPosition;
 21  
 import java.text.Format;
 22  
 import java.text.ParseException;
 23  
 import java.text.ParsePosition;
 24  
 import java.util.Calendar;
 25  
 import java.util.Date;
 26  
 import java.util.Locale;
 27  
 import java.util.TimeZone;
 28  
 
 29  
 /**
 30  
  * <p>FastDateFormat is a fast and thread-safe version of
 31  
  * {@link java.text.SimpleDateFormat}.</p>
 32  
  *
 33  
  * <p>To obtain an instance of FastDateFormat, use one of the static factory methods: 
 34  
  * {@link #getInstance(String, TimeZone, Locale)}, {@link #getDateInstance(int, TimeZone, Locale)}, 
 35  
  * {@link #getTimeInstance(int, TimeZone, Locale)}, or {@link #getDateTimeInstance(int, int, TimeZone, Locale)} 
 36  
  * </p>
 37  
  * 
 38  
  * <p>Since FastDateFormat is thread safe, you can use a static member instance:</p>
 39  
  * <code>
 40  
  *   private static final FastDateFormat DATE_FORMATTER = FastDateFormat.getDateTimeInstance(FastDateFormat.LONG, FastDateFormat.SHORT);
 41  
  * </code>
 42  
  * 
 43  
  * <p>This class can be used as a direct replacement to
 44  
  * {@code SimpleDateFormat} in most formatting and parsing situations.
 45  
  * This class is especially useful in multi-threaded server environments.
 46  
  * {@code SimpleDateFormat} is not thread-safe in any JDK version,
 47  
  * nor will it be as Sun have closed the bug/RFE.
 48  
  * </p>
 49  
  *
 50  
  * <p>All patterns are compatible with
 51  
  * SimpleDateFormat (except time zones and some year patterns - see below).</p>
 52  
  *
 53  
  * <p>Since 3.2, FastDateFormat supports parsing as well as printing.</p>
 54  
  *
 55  
  * <p>Java 1.4 introduced a new pattern letter, {@code 'Z'}, to represent
 56  
  * time zones in RFC822 format (eg. {@code +0800} or {@code -1100}).
 57  
  * This pattern letter can be used here (on all JDK versions).</p>
 58  
  *
 59  
  * <p>In addition, the pattern {@code 'ZZ'} has been made to represent
 60  
  * ISO 8601 full format time zones (eg. {@code +08:00} or {@code -11:00}).
 61  
  * This introduces a minor incompatibility with Java 1.4, but at a gain of
 62  
  * useful functionality.</p>
 63  
  *
 64  
  * <p>Javadoc cites for the year pattern: <i>For formatting, if the number of
 65  
  * pattern letters is 2, the year is truncated to 2 digits; otherwise it is
 66  
  * interpreted as a number.</i> Starting with Java 1.7 a pattern of 'Y' or
 67  
  * 'YYY' will be formatted as '2003', while it was '03' in former Java
 68  
  * versions. FastDateFormat implements the behavior of Java 7.</p>
 69  
  *
 70  
  * @since 2.0
 71  
  */
 72  
 public class FastDateFormat extends Format implements DateParser, DatePrinter {
 73  
     /**
 74  
      * Required for serialization support.
 75  
      *
 76  
      * @see java.io.Serializable
 77  
      */
 78  
     private static final long serialVersionUID = 2L;
 79  
 
 80  
     /**
 81  
      * FULL locale dependent date or time style.
 82  
      */
 83  
     public static final int FULL = DateFormat.FULL;
 84  
     /**
 85  
      * LONG locale dependent date or time style.
 86  
      */
 87  
     public static final int LONG = DateFormat.LONG;
 88  
     /**
 89  
      * MEDIUM locale dependent date or time style.
 90  
      */
 91  
     public static final int MEDIUM = DateFormat.MEDIUM;
 92  
     /**
 93  
      * SHORT locale dependent date or time style.
 94  
      */
 95  
     public static final int SHORT = DateFormat.SHORT;
 96  
 
 97  1377
     private static final FormatCache<FastDateFormat> cache= new FormatCache<FastDateFormat>() {
 98  
         @Override
 99  
         protected FastDateFormat createInstance(final String pattern, final TimeZone timeZone, final Locale locale) {
 100  1376
             return new FastDateFormat(pattern, timeZone, locale);
 101  
         }
 102  
     };
 103  
 
 104  
     private final FastDatePrinter printer;
 105  
     private final FastDateParser parser;
 106  
 
 107  
     //-----------------------------------------------------------------------
 108  
     /**
 109  
      * <p>Gets a formatter instance using the default pattern in the
 110  
      * default locale.</p>
 111  
      *
 112  
      * @return a date/time formatter
 113  
      */
 114  
     public static FastDateFormat getInstance() {
 115  3
         return cache.getInstance();
 116  
     }
 117  
 
 118  
     /**
 119  
      * <p>Gets a formatter instance using the specified pattern in the
 120  
      * default locale.</p>
 121  
      *
 122  
      * @param pattern  {@link java.text.SimpleDateFormat} compatible
 123  
      *  pattern
 124  
      * @return a pattern based date/time formatter
 125  
      * @throws IllegalArgumentException if pattern is invalid
 126  
      */
 127  
     public static FastDateFormat getInstance(final String pattern) {
 128  23
         return cache.getInstance(pattern, null, null);
 129  
     }
 130  
 
 131  
     /**
 132  
      * <p>Gets a formatter instance using the specified pattern and
 133  
      * time zone.</p>
 134  
      *
 135  
      * @param pattern  {@link java.text.SimpleDateFormat} compatible
 136  
      *  pattern
 137  
      * @param timeZone  optional time zone, overrides time zone of
 138  
      *  formatted date
 139  
      * @return a pattern based date/time formatter
 140  
      * @throws IllegalArgumentException if pattern is invalid
 141  
      */
 142  
     public static FastDateFormat getInstance(final String pattern, final TimeZone timeZone) {
 143  633
         return cache.getInstance(pattern, timeZone, null);
 144  
     }
 145  
 
 146  
     /**
 147  
      * <p>Gets a formatter instance using the specified pattern and
 148  
      * locale.</p>
 149  
      *
 150  
      * @param pattern  {@link java.text.SimpleDateFormat} compatible
 151  
      *  pattern
 152  
      * @param locale  optional locale, overrides system locale
 153  
      * @return a pattern based date/time formatter
 154  
      * @throws IllegalArgumentException if pattern is invalid
 155  
      */
 156  
     public static FastDateFormat getInstance(final String pattern, final Locale locale) {
 157  4
         return cache.getInstance(pattern, null, locale);
 158  
     }
 159  
 
 160  
     /**
 161  
      * <p>Gets a formatter instance using the specified pattern, time zone
 162  
      * and locale.</p>
 163  
      *
 164  
      * @param pattern  {@link java.text.SimpleDateFormat} compatible
 165  
      *  pattern
 166  
      * @param timeZone  optional time zone, overrides time zone of
 167  
      *  formatted date
 168  
      * @param locale  optional locale, overrides system locale
 169  
      * @return a pattern based date/time formatter
 170  
      * @throws IllegalArgumentException if pattern is invalid
 171  
      *  or {@code null}
 172  
      */
 173  
     public static FastDateFormat getInstance(final String pattern, final TimeZone timeZone, final Locale locale) {
 174  1396
         return cache.getInstance(pattern, timeZone, locale);
 175  
     }
 176  
 
 177  
     //-----------------------------------------------------------------------
 178  
     /**
 179  
      * <p>Gets a date formatter instance using the specified style in the
 180  
      * default time zone and locale.</p>
 181  
      *
 182  
      * @param style  date style: FULL, LONG, MEDIUM, or SHORT
 183  
      * @return a localized standard date formatter
 184  
      * @throws IllegalArgumentException if the Locale has no date
 185  
      *  pattern defined
 186  
      * @since 2.1
 187  
      */
 188  
     public static FastDateFormat getDateInstance(final int style) {
 189  3
         return cache.getDateInstance(style, null, null);
 190  
     }
 191  
 
 192  
     /**
 193  
      * <p>Gets a date formatter instance using the specified style and
 194  
      * locale in the default time zone.</p>
 195  
      *
 196  
      * @param style  date style: FULL, LONG, MEDIUM, or SHORT
 197  
      * @param locale  optional locale, overrides system locale
 198  
      * @return a localized standard date formatter
 199  
      * @throws IllegalArgumentException if the Locale has no date
 200  
      *  pattern defined
 201  
      * @since 2.1
 202  
      */
 203  
     public static FastDateFormat getDateInstance(final int style, final Locale locale) {
 204  2
         return cache.getDateInstance(style, null, locale);
 205  
     }
 206  
 
 207  
     /**
 208  
      * <p>Gets a date formatter instance using the specified style and
 209  
      * time zone in the default locale.</p>
 210  
      *
 211  
      * @param style  date style: FULL, LONG, MEDIUM, or SHORT
 212  
      * @param timeZone  optional time zone, overrides time zone of
 213  
      *  formatted date
 214  
      * @return a localized standard date formatter
 215  
      * @throws IllegalArgumentException if the Locale has no date
 216  
      *  pattern defined
 217  
      * @since 2.1
 218  
      */
 219  
     public static FastDateFormat getDateInstance(final int style, final TimeZone timeZone) {
 220  1
         return cache.getDateInstance(style, timeZone, null);
 221  
     }
 222  
 
 223  
     /**
 224  
      * <p>Gets a date formatter instance using the specified style, time
 225  
      * zone and locale.</p>
 226  
      *
 227  
      * @param style  date style: FULL, LONG, MEDIUM, or SHORT
 228  
      * @param timeZone  optional time zone, overrides time zone of
 229  
      *  formatted date
 230  
      * @param locale  optional locale, overrides system locale
 231  
      * @return a localized standard date formatter
 232  
      * @throws IllegalArgumentException if the Locale has no date
 233  
      *  pattern defined
 234  
      */
 235  
     public static FastDateFormat getDateInstance(final int style, final TimeZone timeZone, final Locale locale) {
 236  3
         return cache.getDateInstance(style, timeZone, locale);
 237  
     }
 238  
 
 239  
     //-----------------------------------------------------------------------
 240  
     /**
 241  
      * <p>Gets a time formatter instance using the specified style in the
 242  
      * default time zone and locale.</p>
 243  
      *
 244  
      * @param style  time style: FULL, LONG, MEDIUM, or SHORT
 245  
      * @return a localized standard time formatter
 246  
      * @throws IllegalArgumentException if the Locale has no time
 247  
      *  pattern defined
 248  
      * @since 2.1
 249  
      */
 250  
     public static FastDateFormat getTimeInstance(final int style) {
 251  1
         return cache.getTimeInstance(style, null, null);
 252  
     }
 253  
 
 254  
     /**
 255  
      * <p>Gets a time formatter instance using the specified style and
 256  
      * locale in the default time zone.</p>
 257  
      *
 258  
      * @param style  time style: FULL, LONG, MEDIUM, or SHORT
 259  
      * @param locale  optional locale, overrides system locale
 260  
      * @return a localized standard time formatter
 261  
      * @throws IllegalArgumentException if the Locale has no time
 262  
      *  pattern defined
 263  
      * @since 2.1
 264  
      */
 265  
     public static FastDateFormat getTimeInstance(final int style, final Locale locale) {
 266  1
         return cache.getTimeInstance(style, null, locale);
 267  
     }
 268  
 
 269  
     /**
 270  
      * <p>Gets a time formatter instance using the specified style and
 271  
      * time zone in the default locale.</p>
 272  
      *
 273  
      * @param style  time style: FULL, LONG, MEDIUM, or SHORT
 274  
      * @param timeZone  optional time zone, overrides time zone of
 275  
      *  formatted time
 276  
      * @return a localized standard time formatter
 277  
      * @throws IllegalArgumentException if the Locale has no time
 278  
      *  pattern defined
 279  
      * @since 2.1
 280  
      */
 281  
     public static FastDateFormat getTimeInstance(final int style, final TimeZone timeZone) {
 282  1
         return cache.getTimeInstance(style, timeZone, null);
 283  
     }
 284  
 
 285  
     /**
 286  
      * <p>Gets a time formatter instance using the specified style, time
 287  
      * zone and locale.</p>
 288  
      *
 289  
      * @param style  time style: FULL, LONG, MEDIUM, or SHORT
 290  
      * @param timeZone  optional time zone, overrides time zone of
 291  
      *  formatted time
 292  
      * @param locale  optional locale, overrides system locale
 293  
      * @return a localized standard time formatter
 294  
      * @throws IllegalArgumentException if the Locale has no time
 295  
      *  pattern defined
 296  
      */
 297  
     public static FastDateFormat getTimeInstance(final int style, final TimeZone timeZone, final Locale locale) {
 298  3
         return cache.getTimeInstance(style, timeZone, locale);
 299  
     }
 300  
 
 301  
     //-----------------------------------------------------------------------
 302  
     /**
 303  
      * <p>Gets a date/time formatter instance using the specified style
 304  
      * in the default time zone and locale.</p>
 305  
      *
 306  
      * @param dateStyle  date style: FULL, LONG, MEDIUM, or SHORT
 307  
      * @param timeStyle  time style: FULL, LONG, MEDIUM, or SHORT
 308  
      * @return a localized standard date/time formatter
 309  
      * @throws IllegalArgumentException if the Locale has no date/time
 310  
      *  pattern defined
 311  
      * @since 2.1
 312  
      */
 313  
     public static FastDateFormat getDateTimeInstance(final int dateStyle, final int timeStyle) {
 314  4
         return cache.getDateTimeInstance(dateStyle, timeStyle, null, null);
 315  
     }
 316  
 
 317  
     /**
 318  
      * <p>Gets a date/time formatter instance using the specified style and
 319  
      * locale in the default time zone.</p>
 320  
      *
 321  
      * @param dateStyle  date style: FULL, LONG, MEDIUM, or SHORT
 322  
      * @param timeStyle  time style: FULL, LONG, MEDIUM, or SHORT
 323  
      * @param locale  optional locale, overrides system locale
 324  
      * @return a localized standard date/time formatter
 325  
      * @throws IllegalArgumentException if the Locale has no date/time
 326  
      *  pattern defined
 327  
      * @since 2.1
 328  
      */
 329  
     public static FastDateFormat getDateTimeInstance(final int dateStyle, final int timeStyle, final Locale locale) {
 330  6
         return cache.getDateTimeInstance(dateStyle, timeStyle, null, locale);
 331  
     }
 332  
 
 333  
     /**
 334  
      * <p>Gets a date/time formatter instance using the specified style and
 335  
      * time zone in the default locale.</p>
 336  
      *
 337  
      * @param dateStyle  date style: FULL, LONG, MEDIUM, or SHORT
 338  
      * @param timeStyle  time style: FULL, LONG, MEDIUM, or SHORT
 339  
      * @param timeZone  optional time zone, overrides time zone of
 340  
      *  formatted date
 341  
      * @return a localized standard date/time formatter
 342  
      * @throws IllegalArgumentException if the Locale has no date/time
 343  
      *  pattern defined
 344  
      * @since 2.1
 345  
      */
 346  
     public static FastDateFormat getDateTimeInstance(final int dateStyle, final int timeStyle, final TimeZone timeZone) {
 347  1
         return getDateTimeInstance(dateStyle, timeStyle, timeZone, null);
 348  
     }
 349  
     /**
 350  
      * <p>Gets a date/time formatter instance using the specified style,
 351  
      * time zone and locale.</p>
 352  
      *
 353  
      * @param dateStyle  date style: FULL, LONG, MEDIUM, or SHORT
 354  
      * @param timeStyle  time style: FULL, LONG, MEDIUM, or SHORT
 355  
      * @param timeZone  optional time zone, overrides time zone of
 356  
      *  formatted date
 357  
      * @param locale  optional locale, overrides system locale
 358  
      * @return a localized standard date/time formatter
 359  
      * @throws IllegalArgumentException if the Locale has no date/time
 360  
      *  pattern defined
 361  
      */
 362  
     public static FastDateFormat getDateTimeInstance(
 363  
             final int dateStyle, final int timeStyle, final TimeZone timeZone, final Locale locale) {
 364  4
         return cache.getDateTimeInstance(dateStyle, timeStyle, timeZone, locale);
 365  
     }
 366  
 
 367  
     // Constructor
 368  
     //-----------------------------------------------------------------------
 369  
     /**
 370  
      * <p>Constructs a new FastDateFormat.</p>
 371  
      *
 372  
      * @param pattern  {@link java.text.SimpleDateFormat} compatible pattern
 373  
      * @param timeZone  non-null time zone to use
 374  
      * @param locale  non-null locale to use
 375  
      * @throws NullPointerException if pattern, timeZone, or locale is null.
 376  
      */
 377  
     protected FastDateFormat(final String pattern, final TimeZone timeZone, final Locale locale) {
 378  1376
         this(pattern, timeZone, locale, null);
 379  1371
     }
 380  
 
 381  
     // Constructor
 382  
     //-----------------------------------------------------------------------
 383  
     /**
 384  
      * <p>Constructs a new FastDateFormat.</p>
 385  
      *
 386  
      * @param pattern  {@link java.text.SimpleDateFormat} compatible pattern
 387  
      * @param timeZone  non-null time zone to use
 388  
      * @param locale  non-null locale to use
 389  
      * @param centuryStart The start of the 100 year period to use as the "default century" for 2 digit year parsing.  If centuryStart is null, defaults to now - 80 years
 390  
      * @throws NullPointerException if pattern, timeZone, or locale is null.
 391  
      */
 392  1376
     protected FastDateFormat(final String pattern, final TimeZone timeZone, final Locale locale, final Date centuryStart) {
 393  1376
         printer= new FastDatePrinter(pattern, timeZone, locale);
 394  1372
         parser= new FastDateParser(pattern, timeZone, locale, centuryStart);
 395  1371
     }
 396  
 
 397  
     // Format methods
 398  
     //-----------------------------------------------------------------------
 399  
     /**
 400  
      * <p>Formats a {@code Date}, {@code Calendar} or
 401  
      * {@code Long} (milliseconds) object.</p>
 402  
      *
 403  
      * @param obj  the object to format
 404  
      * @param toAppendTo  the buffer to append to
 405  
      * @param pos  the position - ignored
 406  
      * @return the buffer passed in
 407  
      */
 408  
     @Override
 409  
     public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) {
 410  199995
         return printer.format(obj, toAppendTo, pos);
 411  
     }
 412  
 
 413  
     /**
 414  
      * <p>Formats a millisecond {@code long} value.</p>
 415  
      *
 416  
      * @param millis  the millisecond value to format
 417  
      * @return the formatted string
 418  
      * @since 2.1
 419  
      */
 420  
     @Override
 421  
     public String format(final long millis) {
 422  6
         return printer.format(millis);
 423  
     }
 424  
 
 425  
     /**
 426  
      * <p>Formats a {@code Date} object using a {@code GregorianCalendar}.</p>
 427  
      *
 428  
      * @param date  the date to format
 429  
      * @return the formatted string
 430  
      */
 431  
     @Override
 432  
     public String format(final Date date) {
 433  160
         return printer.format(date);
 434  
     }
 435  
 
 436  
     /**
 437  
      * <p>Formats a {@code Calendar} object.</p>
 438  
      *
 439  
      * @param calendar  the calendar to format
 440  
      * @return the formatted string
 441  
      */
 442  
     @Override
 443  
     public String format(final Calendar calendar) {
 444  794
         return printer.format(calendar);
 445  
     }
 446  
 
 447  
     /**
 448  
      * <p>Formats a millisecond {@code long} value into the
 449  
      * supplied {@code StringBuffer}.</p>
 450  
      *
 451  
      * @param millis  the millisecond value to format
 452  
      * @param buf  the buffer to format into
 453  
      * @return the specified string buffer
 454  
      * @since 2.1
 455  
      */
 456  
     @Override
 457  
     public StringBuffer format(final long millis, final StringBuffer buf) {
 458  0
         return printer.format(millis, buf);
 459  
     }
 460  
 
 461  
     /**
 462  
      * <p>Formats a {@code Date} object into the
 463  
      * supplied {@code StringBuffer} using a {@code GregorianCalendar}.</p>
 464  
      *
 465  
      * @param date  the date to format
 466  
      * @param buf  the buffer to format into
 467  
      * @return the specified string buffer
 468  
      */
 469  
     @Override
 470  
     public StringBuffer format(final Date date, final StringBuffer buf) {
 471  0
         return printer.format(date, buf);
 472  
     }
 473  
 
 474  
     /**
 475  
      * <p>Formats a {@code Calendar} object into the
 476  
      * supplied {@code StringBuffer}.</p>
 477  
      *
 478  
      * @param calendar  the calendar to format
 479  
      * @param buf  the buffer to format into
 480  
      * @return the specified string buffer
 481  
      */
 482  
     @Override
 483  
     public StringBuffer format(final Calendar calendar, final StringBuffer buf) {
 484  0
         return printer.format(calendar, buf);
 485  
     }
 486  
 
 487  
     // Parsing
 488  
     //-----------------------------------------------------------------------
 489  
 
 490  
 
 491  
     /* (non-Javadoc)
 492  
      * @see DateParser#parse(java.lang.String)
 493  
      */
 494  
     @Override
 495  
     public Date parse(final String source) throws ParseException {
 496  3801
         return parser.parse(source);
 497  
     }
 498  
 
 499  
     /* (non-Javadoc)
 500  
      * @see DateParser#parse(java.lang.String, java.text.ParsePosition)
 501  
      */
 502  
     @Override
 503  
     public Date parse(final String source, final ParsePosition pos) {
 504  0
             return parser.parse(source, pos);
 505  
     }
 506  
 
 507  
     /* (non-Javadoc)
 508  
      * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)
 509  
      */
 510  
     @Override
 511  
     public Object parseObject(final String source, final ParsePosition pos) {
 512  100000
         return parser.parseObject(source, pos);
 513  
     }
 514  
 
 515  
     // Accessors
 516  
     //-----------------------------------------------------------------------
 517  
     /**
 518  
      * <p>Gets the pattern used by this formatter.</p>
 519  
      *
 520  
      * @return the pattern, {@link java.text.SimpleDateFormat} compatible
 521  
      */
 522  
     @Override
 523  
     public String getPattern() {
 524  31
         return printer.getPattern();
 525  
     }
 526  
 
 527  
     /**
 528  
      * <p>Gets the time zone used by this formatter.</p>
 529  
      *
 530  
      * <p>This zone is always used for {@code Date} formatting. </p>
 531  
      *
 532  
      * @return the time zone
 533  
      */
 534  
     @Override
 535  
     public TimeZone getTimeZone() {
 536  10
         return printer.getTimeZone();
 537  
     }
 538  
 
 539  
     /**
 540  
      * <p>Gets the locale used by this formatter.</p>
 541  
      *
 542  
      * @return the locale
 543  
      */
 544  
     @Override
 545  
     public Locale getLocale() {
 546  13
         return printer.getLocale();
 547  
     }
 548  
 
 549  
     /**
 550  
      * <p>Gets an estimate for the maximum string length that the
 551  
      * formatter will produce.</p>
 552  
      *
 553  
      * <p>The actual formatted length will almost always be less than or
 554  
      * equal to this amount.</p>
 555  
      *
 556  
      * @return the maximum formatted length
 557  
      */
 558  
     public int getMaxLengthEstimate() {
 559  0
         return printer.getMaxLengthEstimate();
 560  
     }
 561  
 
 562  
     // Basics
 563  
     //-----------------------------------------------------------------------
 564  
     /**
 565  
      * <p>Compares two objects for equality.</p>
 566  
      *
 567  
      * @param obj  the object to compare to
 568  
      * @return {@code true} if equal
 569  
      */
 570  
     @Override
 571  
     public boolean equals(final Object obj) {
 572  20
         if (obj instanceof FastDateFormat == false) {
 573  2
             return false;
 574  
         }
 575  18
         final FastDateFormat other = (FastDateFormat) obj;
 576  
         // no need to check parser, as it has same invariants as printer
 577  18
         return printer.equals(other.printer);
 578  
     }
 579  
 
 580  
     /**
 581  
      * <p>Returns a hashcode compatible with equals.</p>
 582  
      *
 583  
      * @return a hashcode compatible with equals
 584  
      */
 585  
     @Override
 586  
     public int hashCode() {
 587  18
         return printer.hashCode();
 588  
     }
 589  
 
 590  
     /**
 591  
      * <p>Gets a debugging string version of this formatter.</p>
 592  
      *
 593  
      * @return a debugging string
 594  
      */
 595  
     @Override
 596  
     public String toString() {
 597  2
         return "FastDateFormat[" + printer.getPattern() + "," + printer.getLocale() + "," + printer.getTimeZone().getID() + "]";
 598  
     }
 599  
 
 600  
 
 601  
     /**
 602  
      * <p>Performs the formatting by applying the rules to the
 603  
      * specified calendar.</p>
 604  
      *
 605  
      * @param calendar  the calendar to format
 606  
      * @param buf  the buffer to format into
 607  
      * @return the specified string buffer
 608  
      */
 609  
     protected StringBuffer applyRules(final Calendar calendar, final StringBuffer buf) {
 610  0
         return printer.applyRules(calendar, buf);
 611  
     }
 612  
 
 613  
 
 614  
 }