org.joda.time.convert

Class ConverterManager


public final class ConverterManager
extends java.lang.Object

ConverterManager controls the date and time converters.

This class enables additional conversion classes to be added via addInstantConverter(InstantConverter), which may replace an existing converter. Similar methods exist for duration, time period and interval converters.

This class is threadsafe, so adding/removing converters can be done at any time. Updating the set of convertors is relatively expensive, and so should not be performed often.

The default instant converters are:

The default partial converters are: The default duration converters are: The default time period converters are: The default interval converters are:
Authors:
Stephen Colebourne
Brian S O'Neill
Since:
1.0

Constructor Summary

ConverterManager()
Restricted constructor.

Method Summary

DurationConverter
addDurationConverter(DurationConverter converter)
Adds a converter to the set of converters.
InstantConverter
addInstantConverter(InstantConverter converter)
Adds a converter to the set of converters.
IntervalConverter
addIntervalConverter(IntervalConverter converter)
Adds a converter to the set of converters.
PartialConverter
addPartialConverter(PartialConverter converter)
Adds a converter to the set of converters.
PeriodConverter
addPeriodConverter(PeriodConverter converter)
Adds a converter to the set of converters.
DurationConverter
getDurationConverter(Object object)
Gets the best converter for the object specified.
DurationConverter[]
getDurationConverters()
Gets a copy of the list of converters.
static ConverterManager
getInstance()
InstantConverter
getInstantConverter(Object object)
Gets the best converter for the object specified.
InstantConverter[]
getInstantConverters()
Gets a copy of the set of converters.
IntervalConverter
getIntervalConverter(Object object)
Gets the best converter for the object specified.
IntervalConverter[]
getIntervalConverters()
Gets a copy of the list of converters.
PartialConverter
getPartialConverter(Object object)
Gets the best converter for the object specified.
PartialConverter[]
getPartialConverters()
Gets a copy of the set of converters.
PeriodConverter
getPeriodConverter(Object object)
Gets the best converter for the object specified.
PeriodConverter[]
getPeriodConverters()
Gets a copy of the list of converters.
DurationConverter
removeDurationConverter(DurationConverter converter)
Removes a converter from the set of converters.
InstantConverter
removeInstantConverter(InstantConverter converter)
Removes a converter from the set of converters.
IntervalConverter
removeIntervalConverter(IntervalConverter converter)
Removes a converter from the set of converters.
PartialConverter
removePartialConverter(PartialConverter converter)
Removes a converter from the set of converters.
PeriodConverter
removePeriodConverter(PeriodConverter converter)
Removes a converter from the set of converters.
String
toString()
Gets a debug representation of the object.

Constructor Details

ConverterManager

protected ConverterManager()
Restricted constructor.

Method Details

addDurationConverter

public DurationConverter addDurationConverter(DurationConverter converter)
            throws SecurityException
Adds a converter to the set of converters. If a matching converter is already in the set, the given converter replaces it. If the converter is exactly the same as one already in the set, no changes are made.

The order in which converters are added is not relevent. The best converter is selected by examining the object hierarchy.

Parameters:
converter - the converter to add, null ignored
Returns:
replaced converter, or null

addInstantConverter

public InstantConverter addInstantConverter(InstantConverter converter)
            throws SecurityException
Adds a converter to the set of converters. If a matching converter is already in the set, the given converter replaces it. If the converter is exactly the same as one already in the set, no changes are made.

The order in which converters are added is not relevent. The best converter is selected by examining the object hierarchy.

Parameters:
converter - the converter to add, null ignored
Returns:
replaced converter, or null

addIntervalConverter

public IntervalConverter addIntervalConverter(IntervalConverter converter)
            throws SecurityException
Adds a converter to the set of converters. If a matching converter is already in the set, the given converter replaces it. If the converter is exactly the same as one already in the set, no changes are made.

The order in which converters are added is not relevent. The best converter is selected by examining the object hierarchy.

Parameters:
converter - the converter to add, null ignored
Returns:
replaced converter, or null

addPartialConverter

public PartialConverter addPartialConverter(PartialConverter converter)
            throws SecurityException
Adds a converter to the set of converters. If a matching converter is already in the set, the given converter replaces it. If the converter is exactly the same as one already in the set, no changes are made.

The order in which converters are added is not relevent. The best converter is selected by examining the object hierarchy.

Parameters:
converter - the converter to add, null ignored
Returns:
replaced converter, or null

addPeriodConverter

public PeriodConverter addPeriodConverter(PeriodConverter converter)
            throws SecurityException
Adds a converter to the set of converters. If a matching converter is already in the set, the given converter replaces it. If the converter is exactly the same as one already in the set, no changes are made.

The order in which converters are added is not relevent. The best converter is selected by examining the object hierarchy.

Parameters:
converter - the converter to add, null ignored
Returns:
replaced converter, or null

getDurationConverter

public DurationConverter getDurationConverter(Object object)
Gets the best converter for the object specified.
Parameters:
object - the object to convert
Returns:
the converter to use

getDurationConverters

public DurationConverter[] getDurationConverters()
Gets a copy of the list of converters.
Returns:
the converters, a copy of the real data, never null

getInstance

public static ConverterManager getInstance()

getInstantConverter

public InstantConverter getInstantConverter(Object object)
Gets the best converter for the object specified.
Parameters:
object - the object to convert
Returns:
the converter to use

getInstantConverters

public InstantConverter[] getInstantConverters()
Gets a copy of the set of converters.
Returns:
the converters, a copy of the real data, never null

getIntervalConverter

public IntervalConverter getIntervalConverter(Object object)
Gets the best converter for the object specified.
Parameters:
object - the object to convert
Returns:
the converter to use

getIntervalConverters

public IntervalConverter[] getIntervalConverters()
Gets a copy of the list of converters.
Returns:
the converters, a copy of the real data, never null

getPartialConverter

public PartialConverter getPartialConverter(Object object)
Gets the best converter for the object specified.
Parameters:
object - the object to convert
Returns:
the converter to use

getPartialConverters

public PartialConverter[] getPartialConverters()
Gets a copy of the set of converters.
Returns:
the converters, a copy of the real data, never null

getPeriodConverter

public PeriodConverter getPeriodConverter(Object object)
Gets the best converter for the object specified.
Parameters:
object - the object to convert
Returns:
the converter to use

getPeriodConverters

public PeriodConverter[] getPeriodConverters()
Gets a copy of the list of converters.
Returns:
the converters, a copy of the real data, never null

removeDurationConverter

public DurationConverter removeDurationConverter(DurationConverter converter)
            throws SecurityException
Removes a converter from the set of converters. If the converter was not in the set, no changes are made.
Parameters:
converter - the converter to remove, null ignored
Returns:
replaced converter, or null

removeInstantConverter

public InstantConverter removeInstantConverter(InstantConverter converter)
            throws SecurityException
Removes a converter from the set of converters. If the converter was not in the set, no changes are made.
Parameters:
converter - the converter to remove, null ignored
Returns:
replaced converter, or null

removeIntervalConverter

public IntervalConverter removeIntervalConverter(IntervalConverter converter)
            throws SecurityException
Removes a converter from the set of converters. If the converter was not in the set, no changes are made.
Parameters:
converter - the converter to remove, null ignored
Returns:
replaced converter, or null

removePartialConverter

public PartialConverter removePartialConverter(PartialConverter converter)
            throws SecurityException
Removes a converter from the set of converters. If the converter was not in the set, no changes are made.
Parameters:
converter - the converter to remove, null ignored
Returns:
replaced converter, or null

removePeriodConverter

public PeriodConverter removePeriodConverter(PeriodConverter converter)
            throws SecurityException
Removes a converter from the set of converters. If the converter was not in the set, no changes are made.
Parameters:
converter - the converter to remove, null ignored
Returns:
replaced converter, or null

toString

public String toString()
Gets a debug representation of the object.

Copyright (c) 2001-2006 - Joda.org