Class ConverterManager
- java.lang.Object
-
- org.joda.time.convert.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 converters 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)
- ReadablePartial
- ReadableInstant
- String
- Calendar
- Date (includes sql package subclasses)
- Long (milliseconds)
- null (now)
- ReadableDuration
- ReadableInterval
- String
- Long (milliseconds)
- null (zero ms)
- ReadablePeriod
- ReadableInterval
- String
- null (zero)
- ReadableInterval
- String
- null (zero-length from now to now)
- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private ConverterSet
iDurationConverters
private ConverterSet
iInstantConverters
private ConverterSet
iIntervalConverters
private static ConverterManager
INSTANCE
Singleton instance, lazily loaded to avoid class loading.private ConverterSet
iPartialConverters
private ConverterSet
iPeriodConverters
-
Constructor Summary
Constructors Modifier Constructor Description protected
ConverterManager()
Restricted constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.private void
checkAlterDurationConverters()
Checks whether the user has permission 'ConverterManager.alterDurationConverters'.private void
checkAlterInstantConverters()
Checks whether the user has permission 'ConverterManager.alterInstantConverters'.private void
checkAlterIntervalConverters()
Checks whether the user has permission 'ConverterManager.alterIntervalConverters'.private void
checkAlterPartialConverters()
Checks whether the user has permission 'ConverterManager.alterPartialConverters'.private void
checkAlterPeriodConverters()
Checks whether the user has permission 'ConverterManager.alterPeriodConverters'.DurationConverter
getDurationConverter(java.lang.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(java.lang.Object object)
Gets the best converter for the object specified.InstantConverter[]
getInstantConverters()
Gets a copy of the set of converters.IntervalConverter
getIntervalConverter(java.lang.Object object)
Gets the best converter for the object specified.IntervalConverter[]
getIntervalConverters()
Gets a copy of the list of converters.PartialConverter
getPartialConverter(java.lang.Object object)
Gets the best converter for the object specified.PartialConverter[]
getPartialConverters()
Gets a copy of the set of converters.PeriodConverter
getPeriodConverter(java.lang.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.java.lang.String
toString()
Gets a debug representation of the object.
-
-
-
Field Detail
-
INSTANCE
private static ConverterManager INSTANCE
Singleton instance, lazily loaded to avoid class loading.
-
iInstantConverters
private ConverterSet iInstantConverters
-
iPartialConverters
private ConverterSet iPartialConverters
-
iDurationConverters
private ConverterSet iDurationConverters
-
iPeriodConverters
private ConverterSet iPeriodConverters
-
iIntervalConverters
private ConverterSet iIntervalConverters
-
-
Method Detail
-
getInstance
public static ConverterManager getInstance()
-
getInstantConverter
public InstantConverter getInstantConverter(java.lang.Object object)
Gets the best converter for the object specified.- Parameters:
object
- the object to convert- Returns:
- the converter to use
- Throws:
java.lang.IllegalArgumentException
- if no suitable converterjava.lang.IllegalStateException
- if multiple converters match the type equally well
-
getInstantConverters
public InstantConverter[] getInstantConverters()
Gets a copy of the set of converters.- Returns:
- the converters, a copy of the real data, never null
-
addInstantConverter
public InstantConverter addInstantConverter(InstantConverter converter) throws java.lang.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 relevant. The best converter is selected by examining the object hierarchy.
- Parameters:
converter
- the converter to add, null ignored- Returns:
- replaced converter, or null
- Throws:
java.lang.SecurityException
-
removeInstantConverter
public InstantConverter removeInstantConverter(InstantConverter converter) throws java.lang.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
- Throws:
java.lang.SecurityException
-
checkAlterInstantConverters
private void checkAlterInstantConverters() throws java.lang.SecurityException
Checks whether the user has permission 'ConverterManager.alterInstantConverters'.- Throws:
java.lang.SecurityException
- if the user does not have the permission
-
getPartialConverter
public PartialConverter getPartialConverter(java.lang.Object object)
Gets the best converter for the object specified.- Parameters:
object
- the object to convert- Returns:
- the converter to use
- Throws:
java.lang.IllegalArgumentException
- if no suitable converterjava.lang.IllegalStateException
- if multiple converters match the type equally well
-
getPartialConverters
public PartialConverter[] getPartialConverters()
Gets a copy of the set of converters.- Returns:
- the converters, a copy of the real data, never null
-
addPartialConverter
public PartialConverter addPartialConverter(PartialConverter converter) throws java.lang.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 relevant. The best converter is selected by examining the object hierarchy.
- Parameters:
converter
- the converter to add, null ignored- Returns:
- replaced converter, or null
- Throws:
java.lang.SecurityException
-
removePartialConverter
public PartialConverter removePartialConverter(PartialConverter converter) throws java.lang.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
- Throws:
java.lang.SecurityException
-
checkAlterPartialConverters
private void checkAlterPartialConverters() throws java.lang.SecurityException
Checks whether the user has permission 'ConverterManager.alterPartialConverters'.- Throws:
java.lang.SecurityException
- if the user does not have the permission
-
getDurationConverter
public DurationConverter getDurationConverter(java.lang.Object object)
Gets the best converter for the object specified.- Parameters:
object
- the object to convert- Returns:
- the converter to use
- Throws:
java.lang.IllegalArgumentException
- if no suitable converterjava.lang.IllegalStateException
- if multiple converters match the type equally well
-
getDurationConverters
public DurationConverter[] getDurationConverters()
Gets a copy of the list of converters.- Returns:
- the converters, a copy of the real data, never null
-
addDurationConverter
public DurationConverter addDurationConverter(DurationConverter converter) throws java.lang.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 relevant. The best converter is selected by examining the object hierarchy.
- Parameters:
converter
- the converter to add, null ignored- Returns:
- replaced converter, or null
- Throws:
java.lang.SecurityException
-
removeDurationConverter
public DurationConverter removeDurationConverter(DurationConverter converter) throws java.lang.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
- Throws:
java.lang.SecurityException
-
checkAlterDurationConverters
private void checkAlterDurationConverters() throws java.lang.SecurityException
Checks whether the user has permission 'ConverterManager.alterDurationConverters'.- Throws:
java.lang.SecurityException
- if the user does not have the permission
-
getPeriodConverter
public PeriodConverter getPeriodConverter(java.lang.Object object)
Gets the best converter for the object specified.- Parameters:
object
- the object to convert- Returns:
- the converter to use
- Throws:
java.lang.IllegalArgumentException
- if no suitable converterjava.lang.IllegalStateException
- if multiple converters match the type equally well
-
getPeriodConverters
public PeriodConverter[] getPeriodConverters()
Gets a copy of the list of converters.- Returns:
- the converters, a copy of the real data, never null
-
addPeriodConverter
public PeriodConverter addPeriodConverter(PeriodConverter converter) throws java.lang.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 relevant. The best converter is selected by examining the object hierarchy.
- Parameters:
converter
- the converter to add, null ignored- Returns:
- replaced converter, or null
- Throws:
java.lang.SecurityException
-
removePeriodConverter
public PeriodConverter removePeriodConverter(PeriodConverter converter) throws java.lang.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
- Throws:
java.lang.SecurityException
-
checkAlterPeriodConverters
private void checkAlterPeriodConverters() throws java.lang.SecurityException
Checks whether the user has permission 'ConverterManager.alterPeriodConverters'.- Throws:
java.lang.SecurityException
- if the user does not have the permission
-
getIntervalConverter
public IntervalConverter getIntervalConverter(java.lang.Object object)
Gets the best converter for the object specified.- Parameters:
object
- the object to convert- Returns:
- the converter to use
- Throws:
java.lang.IllegalArgumentException
- if no suitable converterjava.lang.IllegalStateException
- if multiple converters match the type equally well
-
getIntervalConverters
public IntervalConverter[] getIntervalConverters()
Gets a copy of the list of converters.- Returns:
- the converters, a copy of the real data, never null
-
addIntervalConverter
public IntervalConverter addIntervalConverter(IntervalConverter converter) throws java.lang.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 relevant. The best converter is selected by examining the object hierarchy.
- Parameters:
converter
- the converter to add, null ignored- Returns:
- replaced converter, or null
- Throws:
java.lang.SecurityException
-
removeIntervalConverter
public IntervalConverter removeIntervalConverter(IntervalConverter converter) throws java.lang.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
- Throws:
java.lang.SecurityException
-
checkAlterIntervalConverters
private void checkAlterIntervalConverters() throws java.lang.SecurityException
Checks whether the user has permission 'ConverterManager.alterIntervalConverters'.- Throws:
java.lang.SecurityException
- if the user does not have the permission
-
toString
public java.lang.String toString()
Gets a debug representation of the object.- Overrides:
toString
in classjava.lang.Object
-
-