public final class

ConverterManager

extends Object
java.lang.Object
   ↳ org.joda.time.convert.ConverterManager

Class Overview

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:

  • ReadableInstant
  • String
  • Calendar
  • Date (includes sql package subclasses)
  • Long (milliseconds)
  • null (now)
The default partial converters are:
  • ReadablePartial
  • ReadableInstant
  • String
  • Calendar
  • Date (includes sql package subclasses)
  • Long (milliseconds)
  • null (now)
The default duration converters are:
  • ReadableDuration
  • ReadableInterval
  • String
  • Long (milliseconds)
  • null (zero ms)
The default time period converters are:
  • ReadablePeriod
  • ReadableInterval
  • String
  • null (zero)
The default interval converters are:
  • ReadableInterval
  • String
  • null (zero-length from now to now)

Summary

Protected Constructors
ConverterManager()
Restricted constructor.
Public Methods
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.
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected ConverterManager ()

Restricted constructor.

Public Methods

public DurationConverter addDurationConverter (DurationConverter converter)

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

public InstantConverter addInstantConverter (InstantConverter converter)

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

public IntervalConverter addIntervalConverter (IntervalConverter converter)

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

public PartialConverter addPartialConverter (PartialConverter converter)

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

public PeriodConverter addPeriodConverter (PeriodConverter converter)

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

public DurationConverter getDurationConverter (Object object)

Gets the best converter for the object specified.

Parameters
object the object to convert
Returns
  • the converter to use
Throws
IllegalArgumentException if no suitable converter
IllegalStateException if multiple converters match the type equally well

public DurationConverter[] getDurationConverters ()

Gets a copy of the list of converters.

Returns
  • the converters, a copy of the real data, never null

public static ConverterManager getInstance ()

public InstantConverter getInstantConverter (Object object)

Gets the best converter for the object specified.

Parameters
object the object to convert
Returns
  • the converter to use
Throws
IllegalArgumentException if no suitable converter
IllegalStateException if multiple converters match the type equally well

public InstantConverter[] getInstantConverters ()

Gets a copy of the set of converters.

Returns
  • the converters, a copy of the real data, never null

public IntervalConverter getIntervalConverter (Object object)

Gets the best converter for the object specified.

Parameters
object the object to convert
Returns
  • the converter to use
Throws
IllegalArgumentException if no suitable converter
IllegalStateException if multiple converters match the type equally well

public IntervalConverter[] getIntervalConverters ()

Gets a copy of the list of converters.

Returns
  • the converters, a copy of the real data, never null

public PartialConverter getPartialConverter (Object object)

Gets the best converter for the object specified.

Parameters
object the object to convert
Returns
  • the converter to use
Throws
IllegalArgumentException if no suitable converter
IllegalStateException if multiple converters match the type equally well

public PartialConverter[] getPartialConverters ()

Gets a copy of the set of converters.

Returns
  • the converters, a copy of the real data, never null

public PeriodConverter getPeriodConverter (Object object)

Gets the best converter for the object specified.

Parameters
object the object to convert
Returns
  • the converter to use
Throws
IllegalArgumentException if no suitable converter
IllegalStateException if multiple converters match the type equally well

public PeriodConverter[] getPeriodConverters ()

Gets a copy of the list of converters.

Returns
  • the converters, a copy of the real data, never null

public DurationConverter removeDurationConverter (DurationConverter converter)

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

public InstantConverter removeInstantConverter (InstantConverter converter)

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

public IntervalConverter removeIntervalConverter (IntervalConverter converter)

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

public PartialConverter removePartialConverter (PartialConverter converter)

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

public PeriodConverter removePeriodConverter (PeriodConverter converter)

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

public String toString ()

Gets a debug representation of the object.