public final class Converters extends Object implements ConverterProvider
Values.
Converters instances compute Converters on
demand in many cases and are normally used in standalone
environments.
| Constructor and Description |
|---|
Converters()
Creates a new
Converters instance. |
Converters(Collection<? extends Converter<?>> converters)
Creates a new
Converters instance. |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
convert(Value value,
Class<T> type)
Converts the supplied
Value to an object of the proper
type and returns the result of the conversion using a Converter previously
installed under a Type equal to the supplied Class. |
<T> T |
convert(Value value,
TypeLiteral<T> type)
Converts the supplied
Value to an object of the proper
type and returns the result of the conversion using a Converter previously
installed under a Type equal to the supplied TypeLiteral's Type. |
<T> Converter<? extends T> |
getConverter(Class<T> type)
|
Converter<?> |
getConverter(Type type)
|
<T> Converter<? extends T> |
getConverter(TypeLiteral<T> type)
|
<T> Converter<? extends T> |
putConverter(Class<T> type,
Converter<? extends T> converter)
|
<T> Converter<? extends T> |
putConverter(TypeLiteral<T> type,
Converter<? extends T> converter)
|
<T> Converter<? extends T> |
removeConverter(Class<T> key)
Uninstalls and returns any
Converter stored under a key
equal to the supplied key. |
<T> Converter<? extends T> |
removeConverter(TypeLiteral<T> key)
Uninstalls and returns any
Converter stored under a key
equal to the supplied key. |
public Converters()
Converters instance.public Converters(Collection<? extends Converter<?>> converters)
Converters instance.converters - a Collection of Converters that
will be installed into this Converters instance; may be nullConcurrentModificationException - if some
other thread modifies the supplied Collection while
iteration is in progresspublic final <T> Converter<? extends T> getConverter(TypeLiteral<T> type)
getConverter in interface ConverterProviderT - the conversion typetype - a TypeLiteral describing the conversion type;
must not be nullnull Converter capable of
converting Values
into objects of the proper typeNullPointerException - if type is nullIllegalArgumentException - if no Converter is
available for the supplied typeConverterProvider.getConverter(Type)Converters can be added to this
Converters instance, this method may return
different Converter instances over time given the same
type.null.public final <T> Converter<? extends T> getConverter(Class<T> type)
getConverter in interface ConverterProviderT - the conversion typetype - a Class describing the conversion type; must
not be nullnull Converter capable of
converting Values
into objects of the proper typeNullPointerException - if type is nullIllegalArgumentException - if no Converter is
available for the supplied typeConverterProvider.getConverter(Type)Converters can be added to this
Converters instance, this method may return
different Converter instances over time given the same
type.null.public final Converter<?> getConverter(Type type)
getConverter in interface ConverterProvidertype - a Type describing the conversion type; must
not be nullnull Converter capable of
converting Values
into objects of the proper typeNullPointerException - if type is nullIllegalArgumentException - if no Converter is
available for the supplied typeConverters can be added to this
Converters instance, this method may return
different Converter instances over time given the same
type.null.public final <T> Converter<? extends T> putConverter(Class<T> type, Converter<? extends T> converter)
Converter under the supplied Class and returns any Converter previously installed
under a Type equal to that Class.T - the conversion typetype - the Class describing the conversion type of
the supplied Converter; must not be nullconverter - the Converter to install; must not be
nullConverter previously installed under a Type equal to the supplied Class, or nullNullPointerException - if type or converter is nullgetConverter(Class)null.public final <T> Converter<? extends T> putConverter(TypeLiteral<T> type, Converter<? extends T> converter)
Converter under the supplied TypeLiteral's Type and returns any
Converter previously installed under a Type equal
to that Type.T - the conversion typetype - the TypeLiteral describing the conversion
type of the supplied Converter; must not be nullconverter - the Converter to install; must not be
nullConverter previously installed under a Type equal to the supplied TypeLiteral's Type, or nullNullPointerException - if type or converter is nullgetConverter(TypeLiteral)null.public final <T> Converter<? extends T> removeConverter(Class<T> key)
Converter stored under a key
equal to the supplied key.T - the conversion typekey - the key designating the Converter to remove;
must not be nullConverter that was uninstalled, or nullNullPointerException - if key is nullConverter stored under a key equal to the supplied key,
and, if then invoked with the same key, will return
null thereafter.null.public final <T> Converter<? extends T> removeConverter(TypeLiteral<T> key)
Converter stored under a key
equal to the supplied key.T - the conversion typekey - the key designating the Converter to remove;
must not be nullConverter that was uninstalled, or nullNullPointerException - if key is nullConverter stored under a key equal to the supplied key,
and, if then invoked with the same key, will return
null thereafter.null.public final <T> T convert(Value value, Class<T> type)
Value to an object of the proper
type and returns the result of the conversion using a Converter previously
installed under a Type equal to the supplied Class.T - the conversion typevalue - the Value to convert; may be nulltype - the Class designating the Converter to use; must not be nullnullNullPointerException - if type is nullIllegalArgumentException - if conversion fails because
of a problem with the supplied ValueConversionException - if conversion fails for any other
reasonnull.public final <T> T convert(Value value, TypeLiteral<T> type)
Value to an object of the proper
type and returns the result of the conversion using a Converter previously
installed under a Type equal to the supplied TypeLiteral's Type.T - the conversion typevalue - the Value to convert; may be nulltype - the TypeLiteral designating the Converter to use; must not be nullnullNullPointerException - if type is nullIllegalArgumentException - if conversion fails because
of a problem with the supplied ValueConversionException - if conversion fails for any other
reasonnull.Copyright © 2019–2020, microBean™. All rights reserved.