FileDocCategorySizeDatePackage
SynchronizedDateFormat.javaAPI DocApache James 2.3.15584Fri Jan 12 12:56:36 GMT 2007org.apache.mailet.dates

SynchronizedDateFormat

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.

Fields Summary
private final DateFormat
internalDateFormat
Constructors Summary
public SynchronizedDateFormat(String pattern, Locale locale)
Public constructor that mimics that of SimpleDateFormat. See java.text.SimpleDateFormat for more details.

param
pattern the pattern that defines this DateFormat
param
locale the locale

        internalDateFormat = new SimpleDateFormat(pattern, locale);
    
protected SynchronizedDateFormat(DateFormat theDateFormat)

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

TODO: Investigate replacing this with a factory method.

param
the DateFormat to synchronize

        internalDateFormat = theDateFormat;
    
Methods Summary
public booleanequals(java.lang.Object obj)
Overrides equals

        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        synchronized(internalDateFormat) {
            return internalDateFormat.equals(obj);
        }
    
public java.lang.Stringformat(java.util.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.

return
java.lang.String
param
d Date

        synchronized (internalDateFormat) {
           return internalDateFormat.format(d);
        }
    
public java.util.TimeZonegetTimeZone()
Gets the time zone.

return
the time zone associated with this SynchronizedDateFormat.

        synchronized(internalDateFormat) {
            return internalDateFormat.getTimeZone();
        }
    
public inthashCode()
Overrides hashCode

        synchronized(internalDateFormat) {
            return internalDateFormat.hashCode();
        }
    
public booleanisLenient()
Tell whether date/time parsing is to be lenient.

return
whether this SynchronizedDateFormat is lenient.

        synchronized(internalDateFormat) {
            return internalDateFormat.isLenient();
        }
    
public java.util.Dateparse(java.lang.String source)
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.

param
source A String whose beginning should be parsed.
return
A Date parsed from the string.
throws
ParseException if the beginning of the specified string cannot be parsed.

        synchronized (internalDateFormat) {
            return internalDateFormat.parse(source);
        }
    
public voidsetLenient(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.

param
lenient when true, parsing is lenient
see
java.util.Calendar#setLenient

        synchronized(internalDateFormat) {
            internalDateFormat.setLenient(lenient);
        }
    
public voidsetTimeZone(java.util.TimeZone zone)
Sets the time zone of this SynchronizedDateFormat object.

param
zone the given new time zone.

        synchronized(internalDateFormat) {
            internalDateFormat.setTimeZone(zone);
        }