T - The type of object that this class converts the format of.TFormatType - The class of the format object itself. This can be a base class.public class FormatConverter<T,TFormatType extends IIndexedFormat> extends Object
| Constructor and Description |
|---|
FormatConverter()
Initializes a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
T |
convert(TFormatType from,
TFormatType to,
T instance)
Converts the specified instance from one format to another.
|
FormatConversionCallback<T,TFormatType> |
getConversionCallback(TFormatType from,
TFormatType to)
Gets the callback that converts from one format to another.
|
int |
getConversionDistance(TFormatType from,
TFormatType to)
Gets the number of intermediate conversions that must be done to convert from
from to to. |
void |
registerConversion(TFormatType from,
TFormatType to,
FormatConversionCallback<T,TFormatType> conversion)
Registers a conversion between formats.
|
void |
registerConversion(TFormatType from,
TFormatType to,
FormatConversionCallback<T,TFormatType> conversion,
TryFormatConversionCallback<T,TFormatType> tryConversion)
Registers a conversion between formats.
|
boolean |
tryConvert(TFormatType from,
TFormatType to,
T instance,
T[] result)
Tries to convert the specified instance from one format to another, returning
success or failure.
|
public final T convert(@Nonnull TFormatType from, @Nonnull TFormatType to, T instance)
from - The source TFormatType.to - The destination TFormatType.instance - The instance of T to convert.T equivalent to from,
in the new TFormatType to.ArgumentException - Thrown when there is no conversion defined from from to
to.public final boolean tryConvert(@Nonnull TFormatType from, @Nonnull TFormatType to, T instance, @Nonnull T[] result)
from - The source TFormatType.to - The destination TFormatType.instance - The instance of T to convert.result - On input, an array with one element. On return, the array is populated with
the resulting instance of T
equivalent to from, in the new
TFormatType to.true if from could be converted to the
requested TFormatType to; otherwise false.ArgumentException - Thrown when there is no conversion defined from from to to.@Nullable public final FormatConversionCallback<T,TFormatType> getConversionCallback(@Nonnull TFormatType from, @Nonnull TFormatType to)
from - The source format.to - The destination format.from to to, or null
if a conversion does not exist.public final int getConversionDistance(@Nonnull TFormatType from, @Nonnull TFormatType to)
from to to. For example, if a conversion
function is defined to directly convert between the types, 1 will be returned.
If the two types are identical, 0 will be returned. If no conversion exists
at all, Integer.MAX_VALUE will be returned.from - The source format.to - The destination format.public final void registerConversion(@Nonnull TFormatType from, @Nonnull TFormatType to, @Nonnull FormatConversionCallback<T,TFormatType> conversion)
from - The source format.to - The destination format.conversion - A delegate referring to a function to convert from from to
to.ArgumentException - Thrown when registering a conversion between identical formats. The parameters
from and to cannot be equal.public final void registerConversion(@Nonnull TFormatType from, @Nonnull TFormatType to, @Nonnull FormatConversionCallback<T,TFormatType> conversion, @Nonnull TryFormatConversionCallback<T,TFormatType> tryConversion)
from - The source format.to - The destination format.conversion - A delegate referring to a function to convert from from to
to.tryConversion - A delegate referring to a function to try converting from
from to to, returning success or failure.ArgumentException - Thrown when registering a conversion between identical formats. The parameters
from and to cannot be equal.