java.lang.Object |
↳ |
java.text.Format |
|
↳ |
java.text.DateFormat |
|
|
↳ |
org.apache.log4j.pattern.CachedDateFormat |
Class Overview
CachedDateFormat optimizes the performance of a wrapped
DateFormat. The implementation is not thread-safe.
If the millisecond pattern is not recognized,
the class will only use the cache if the
same value is requested.
Summary
Constants |
int |
NO_MILLISECONDS |
Constant used to represent that there was no change
observed when changing the millisecond count. |
int |
UNRECOGNIZED_MILLISECONDS |
Constant used to represent that there was an
observed change, but was an expected change. |
[Expand]
Inherited Constants |
From class
java.text.DateFormat
int |
AM_PM_FIELD |
|
int |
DATE_FIELD |
|
int |
DAY_OF_WEEK_FIELD |
|
int |
DAY_OF_WEEK_IN_MONTH_FIELD |
|
int |
DAY_OF_YEAR_FIELD |
|
int |
DEFAULT |
|
int |
ERA_FIELD |
|
int |
FULL |
|
int |
HOUR0_FIELD |
|
int |
HOUR1_FIELD |
|
int |
HOUR_OF_DAY0_FIELD |
|
int |
HOUR_OF_DAY1_FIELD |
|
int |
LONG |
|
int |
MEDIUM |
|
int |
MILLISECOND_FIELD |
|
int |
MINUTE_FIELD |
|
int |
MONTH_FIELD |
|
int |
SECOND_FIELD |
|
int |
SHORT |
|
int |
TIMEZONE_FIELD |
|
int |
WEEK_OF_MONTH_FIELD |
|
int |
WEEK_OF_YEAR_FIELD |
|
int |
YEAR_FIELD |
|
|
[Expand]
Inherited Fields |
From class
java.text.DateFormat
protected
Calendar |
calendar |
|
protected
NumberFormat |
numberFormat |
|
|
Public Constructors |
|
CachedDateFormat(DateFormat dateFormat, int expiration)
Creates a new CachedDateFormat object.
|
Public Methods |
static
int
|
findMillisecondStart(long time, String formatted, DateFormat formatter)
Finds start of millisecond field in formatted time.
|
StringBuffer
|
format(Date date, StringBuffer sbuf, FieldPosition fieldPosition)
Formats a Date into a date/time string.
|
StringBuffer
|
format(long now, StringBuffer buf)
Formats a millisecond count into a date/time string.
|
static
int
|
getMaximumCacheValidity(String pattern)
Gets maximum cache validity for the specified SimpleDateTime
conversion pattern.
|
NumberFormat
|
getNumberFormat()
Gets number formatter.
|
Date
|
parse(String s, ParsePosition pos)
This method is delegated to the formatter which most
likely returns null.
|
void
|
setTimeZone(TimeZone timeZone)
Set timezone.
|
[Expand]
Inherited Methods |
From class
java.text.DateFormat
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
abstract
StringBuffer
|
format(Date arg0, StringBuffer arg1, FieldPosition arg2)
|
final
StringBuffer
|
format(Object arg0, StringBuffer arg1, FieldPosition arg2)
|
final
String
|
format(Date arg0)
|
static
Locale[]
|
getAvailableLocales()
|
Calendar
|
getCalendar()
|
final
static
DateFormat
|
getDateInstance(int arg0)
|
final
static
DateFormat
|
getDateInstance(int arg0, Locale arg1)
|
final
static
DateFormat
|
getDateInstance()
|
final
static
DateFormat
|
getDateTimeInstance(int arg0, int arg1, Locale arg2)
|
final
static
DateFormat
|
getDateTimeInstance(int arg0, int arg1)
|
final
static
DateFormat
|
getDateTimeInstance()
|
final
static
DateFormat
|
getInstance()
|
NumberFormat
|
getNumberFormat()
|
final
static
DateFormat
|
getTimeInstance(int arg0)
|
final
static
DateFormat
|
getTimeInstance()
|
final
static
DateFormat
|
getTimeInstance(int arg0, Locale arg1)
|
TimeZone
|
getTimeZone()
|
int
|
hashCode()
|
boolean
|
isLenient()
|
Date
|
parse(String arg0)
|
abstract
Date
|
parse(String arg0, ParsePosition arg1)
|
Object
|
parseObject(String arg0, ParsePosition arg1)
|
void
|
setCalendar(Calendar arg0)
|
void
|
setLenient(boolean arg0)
|
void
|
setNumberFormat(NumberFormat arg0)
|
void
|
setTimeZone(TimeZone arg0)
|
|
From class
java.text.Format
Object
|
clone()
|
final
String
|
format(Object arg0)
|
abstract
StringBuffer
|
format(Object arg0, StringBuffer arg1, FieldPosition arg2)
|
AttributedCharacterIterator
|
formatToCharacterIterator(Object arg0)
|
Object
|
parseObject(String arg0)
|
abstract
Object
|
parseObject(String arg0, ParsePosition arg1)
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
|
Constants
public
static
final
int
NO_MILLISECONDS
Constant used to represent that there was no change
observed when changing the millisecond count.
Constant Value:
-2
(0xfffffffe)
public
static
final
int
UNRECOGNIZED_MILLISECONDS
Constant used to represent that there was an
observed change, but was an expected change.
Constant Value:
-1
(0xffffffff)
Public Constructors
public
CachedDateFormat
(DateFormat dateFormat, int expiration)
Creates a new CachedDateFormat object.
Parameters
dateFormat
| Date format, may not be null. |
expiration
| maximum cached range in milliseconds.
If the dateFormat is known to be incompatible with the
caching algorithm, use a value of 0 to totally disable
caching or 1 to only use cache for duplicate requests.
|
Public Methods
public
static
int
findMillisecondStart
(long time, String formatted, DateFormat formatter)
Finds start of millisecond field in formatted time.
Parameters
time
| long time, must be integral number of seconds |
formatted
| String corresponding formatted string |
formatter
| DateFormat date format |
Returns
- int position in string of first digit of milliseconds,
-1 indicates no millisecond field, -2 indicates unrecognized
field (likely RelativeTimeDateFormat)
public
StringBuffer
format
(Date date, StringBuffer sbuf, FieldPosition fieldPosition)
Formats a Date into a date/time string.
Parameters
date
| the date to format. |
sbuf
| the string buffer to write to. |
fieldPosition
| remains untouched. |
Returns
- the formatted time string.
public
StringBuffer
format
(long now, StringBuffer buf)
Formats a millisecond count into a date/time string.
Parameters
now
| Number of milliseconds after midnight 1 Jan 1970 GMT. |
buf
| the string buffer to write to. |
Returns
- the formatted time string.
public
static
int
getMaximumCacheValidity
(String pattern)
Gets maximum cache validity for the specified SimpleDateTime
conversion pattern.
Parameters
pattern
| conversion pattern, may not be null. |
Returns
- Duration in milliseconds from an integral second
that the cache will return consistent results.
public
NumberFormat
getNumberFormat
()
Returns
- NumberFormat number formatter
public
Date
parse
(String s, ParsePosition pos)
This method is delegated to the formatter which most
likely returns null.
Parameters
s
| string representation of date. |
pos
| field position, unused. |
Returns
- parsed date, likely null.
public
void
setTimeZone
(TimeZone timeZone)
Set timezone.
Setting the timezone using getCalendar().setTimeZone()
will likely cause caching to misbehave.
Parameters
timeZone
| TimeZone new timezone
|