org.apache.mailet.base
Class SynchronizedDateFormat

java.lang.Object
  extended by org.apache.mailet.base.SynchronizedDateFormat
All Implemented Interfaces:
SimplifiedDateFormat
Direct Known Subclasses:
RFC2980DateFormat, RFC822DateFormat

public class SynchronizedDateFormat
extends Object
implements SimplifiedDateFormat

This class is designed to be a synchronized wrapper for a java.text.DateFormat subclass. In general, these subclasses (most notably the java.text.SimpleDateFormat classes are not thread safe, so we need to synchronize on the internal DateFormat for all delegated calls.


Constructor Summary
protected SynchronizedDateFormat(DateFormat theDateFormat)
          Wrapper method to allow child classes to synchronize a preexisting DateFormat.
  SynchronizedDateFormat(String pattern, Locale locale)
          Public constructor that mimics that of SimpleDateFormat.
 
Method Summary
 boolean equals(Object obj)
          Overrides equals
 String format(Date d)
          SimpleDateFormat will handle most of this for us, but we want to ensure thread safety, so we wrap the call in a synchronized block.
 TimeZone getTimeZone()
          Gets the time zone.
 int hashCode()
          Overrides hashCode
 boolean isLenient()
          Tell whether date/time parsing is to be lenient.
 Date parse(String source)
          Parses text from the beginning of the given string to produce a date.
 void setLenient(boolean lenient)
          Specify whether or not date/time parsing is to be lenient.
 void setTimeZone(TimeZone zone)
          Sets the time zone of this SynchronizedDateFormat object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronizedDateFormat

public SynchronizedDateFormat(String pattern,
                              Locale locale)
Public constructor that mimics that of SimpleDateFormat. See java.text.SimpleDateFormat for more details.

Parameters:
pattern - the pattern that defines this DateFormat
locale - the locale

SynchronizedDateFormat

protected SynchronizedDateFormat(DateFormat theDateFormat)

Wrapper method to allow child classes to synchronize a preexisting DateFormat.

TODO: Investigate replacing this with a factory method.

Parameters:
theDateFormat - the DateFormat to synchronize
Method Detail

format

public String format(Date d)
SimpleDateFormat will handle most of this for us, but we want to ensure thread safety, so we wrap the call in a synchronized block.

Specified by:
format in interface SimplifiedDateFormat
Parameters:
d - Date
Returns:
java.lang.String

parse

public Date parse(String source)
           throws ParseException
Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.

This method is designed to be thread safe, so we wrap our delegated parse method in an appropriate synchronized block.

Specified by:
parse in interface SimplifiedDateFormat
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.

setTimeZone

public void setTimeZone(TimeZone zone)
Sets the time zone of this SynchronizedDateFormat object.

Specified by:
setTimeZone in interface SimplifiedDateFormat
Parameters:
zone - the given new time zone.

getTimeZone

public TimeZone getTimeZone()
Gets the time zone.

Specified by:
getTimeZone in interface SimplifiedDateFormat
Returns:
the time zone associated with this SynchronizedDateFormat.

setLenient

public void setLenient(boolean lenient)
Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.

Specified by:
setLenient in interface SimplifiedDateFormat
Parameters:
lenient - when true, parsing is lenient
See Also:
Calendar.setLenient(boolean)

isLenient

public boolean isLenient()
Tell whether date/time parsing is to be lenient.

Specified by:
isLenient in interface SimplifiedDateFormat
Returns:
whether this SynchronizedDateFormat is lenient.

hashCode

public int hashCode()
Overrides hashCode

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides equals

Overrides:
equals in class Object


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.