public class FastDatePrinter extends Object implements DatePrinter, Serializable
Modifier and Type | Field and Description |
---|---|
static int |
FULL
FULL locale dependent date or time style.
|
static int |
LONG
LONG locale dependent date or time style.
|
static int |
MEDIUM
MEDIUM locale dependent date or time style.
|
static int |
SHORT
SHORT locale dependent date or time style.
|
Modifier | Constructor and Description |
---|---|
protected |
FastDatePrinter(String pattern,
TimeZone timeZone,
Locale locale)
Constructs a new FastDatePrinter.
|
Modifier and Type | Method and Description |
---|---|
protected StringBuilder |
applyRules(Calendar calendar,
StringBuilder buf)
Performs the formatting by applying the rules to the specified calendar.
|
boolean |
equals(Object obj)
Compares two objects for equality.
|
String |
format(Calendar calendar)
Formats a
Calendar object. |
StringBuilder |
format(Calendar calendar,
StringBuilder buf)
Formats a
Calendar object into the supplied StringBuilder . |
String |
format(Date date)
Formats a
Date object using a GregorianCalendar . |
StringBuilder |
format(Date date,
StringBuilder buf)
Formats a
Date object into the
supplied StringBuilder using a GregorianCalendar . |
String |
format(long millis)
Formats a millisecond
long value. |
StringBuilder |
format(long millis,
StringBuilder buf)
Formats a milliseond
long value into the
supplied StringBuilder . |
StringBuilder |
format(Object obj,
StringBuilder toAppendTo,
FieldPosition pos)
Formats a
Date , Calendar or Long (milliseconds) object. |
Locale |
getLocale()
Gets the locale used by this printer.
|
int |
getMaxLengthEstimate()
Gets an estimate for the maximum string length that the formatter will produce.
|
String |
getPattern()
Gets the pattern used by this printer.
|
TimeZone |
getTimeZone()
Gets the time zone used by this printer.
|
int |
hashCode()
Returns a hashcode compatible with equals.
|
protected List<org.apache.logging.log4j.core.util.datetime.FastDatePrinter.Rule> |
parsePattern()
Returns a list of Rules given a pattern.
|
protected String |
parseToken(String pattern,
int[] indexRef)
Performs the parsing of tokens.
|
protected org.apache.logging.log4j.core.util.datetime.FastDatePrinter.NumberRule |
selectNumberRule(int field,
int padding)
Gets an appropriate rule for the padding required.
|
String |
toString()
Gets a debugging string version of this formatter.
|
public static final int FULL
public static final int LONG
public static final int MEDIUM
public static final int SHORT
protected FastDatePrinter(String pattern, TimeZone timeZone, Locale locale)
Constructs a new FastDatePrinter.
UseFastDateFormat.getInstance(String, TimeZone, Locale)
or another variation of the factory methods of
FastDateFormat
to get a cached FastDatePrinter instance.pattern
- SimpleDateFormat
compatible patterntimeZone
- non-null time zone to uselocale
- non-null locale to useNullPointerException
- if pattern, timeZone, or locale is null.protected List<org.apache.logging.log4j.core.util.datetime.FastDatePrinter.Rule> parsePattern()
Returns a list of Rules given a pattern.
List
of Rule objectsIllegalArgumentException
- if pattern is invalidprotected String parseToken(String pattern, int[] indexRef)
Performs the parsing of tokens.
pattern
- the patternindexRef
- index referencesprotected org.apache.logging.log4j.core.util.datetime.FastDatePrinter.NumberRule selectNumberRule(int field, int padding)
Gets an appropriate rule for the padding required.
field
- the field to get a rule forpadding
- the padding requiredpublic StringBuilder format(Object obj, StringBuilder toAppendTo, FieldPosition pos)
Formats a Date
, Calendar
or Long
(milliseconds) object.
format
in interface DatePrinter
obj
- the object to formattoAppendTo
- the buffer to append topos
- the position - ignoredpublic String format(long millis)
DatePrinter
Formats a millisecond long
value.
format
in interface DatePrinter
millis
- the millisecond value to formatpublic String format(Date date)
DatePrinter
Formats a Date
object using a GregorianCalendar
.
format
in interface DatePrinter
date
- the date to formatpublic String format(Calendar calendar)
DatePrinter
Formats a Calendar
object.
format
in interface DatePrinter
calendar
- the calendar to format.public StringBuilder format(long millis, StringBuilder buf)
DatePrinter
Formats a milliseond long
value into the
supplied StringBuilder
.
format
in interface DatePrinter
millis
- the millisecond value to formatbuf
- the buffer to format intopublic StringBuilder format(Date date, StringBuilder buf)
DatePrinter
Formats a Date
object into the
supplied StringBuilder
using a GregorianCalendar
.
format
in interface DatePrinter
date
- the date to formatbuf
- the buffer to format intopublic StringBuilder format(Calendar calendar, StringBuilder buf)
DatePrinter
Formats a Calendar
object into the supplied StringBuilder
.
format
in interface DatePrinter
calendar
- the calendar to formatbuf
- the buffer to format intoprotected StringBuilder applyRules(Calendar calendar, StringBuilder buf)
Performs the formatting by applying the rules to the specified calendar.
calendar
- the calendar to formatbuf
- the buffer to format intopublic String getPattern()
DatePrinter
Gets the pattern used by this printer.
getPattern
in interface DatePrinter
SimpleDateFormat
compatiblepublic TimeZone getTimeZone()
DatePrinter
Gets the time zone used by this printer.
This zone is always used for Date
printing.
getTimeZone
in interface DatePrinter
public Locale getLocale()
DatePrinter
Gets the locale used by this printer.
getLocale
in interface DatePrinter
public int getMaxLengthEstimate()
Gets an estimate for the maximum string length that the formatter will produce.
The actual formatted length will almost always be less than or equal to this amount.
public boolean equals(Object obj)
Compares two objects for equality.
public int hashCode()
Returns a hashcode compatible with equals.
Copyright © 1999-2017 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.