public final class Converters extends Object implements ConverterProvider
Value
s.
Converters
instances compute Converter
s 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 Converter
s that
will be installed into this Converters
instance; may be null
ConcurrentModificationException
- 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 ConverterProvider
T
- the conversion typetype
- a TypeLiteral
describing the conversion type;
must not be null
null
Converter
capable of
converting Value
s
into objects of the proper typeNullPointerException
- if type
is null
IllegalArgumentException
- if no Converter
is
available for the supplied type
ConverterProvider.getConverter(Type)
Converter
s 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 ConverterProvider
T
- the conversion typetype
- a Class
describing the conversion type; must
not be null
null
Converter
capable of
converting Value
s
into objects of the proper typeNullPointerException
- if type
is null
IllegalArgumentException
- if no Converter
is
available for the supplied type
ConverterProvider.getConverter(Type)
Converter
s 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 ConverterProvider
type
- a Type
describing the conversion type; must
not be null
null
Converter
capable of
converting Value
s
into objects of the proper typeNullPointerException
- if type
is null
IllegalArgumentException
- if no Converter
is
available for the supplied type
Converter
s 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 null
converter
- the Converter
to install; must not be
null
Converter
previously installed under a Type
equal to the supplied Class
, or null
NullPointerException
- if type
or converter
is null
getConverter(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 null
converter
- the Converter
to install; must not be
null
Converter
previously installed under a Type
equal to the supplied TypeLiteral
's Type
, or null
NullPointerException
- if type
or converter
is null
getConverter(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 null
Converter
that was uninstalled, or null
NullPointerException
- if key
is null
Converter
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 null
Converter
that was uninstalled, or null
NullPointerException
- if key
is null
Converter
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 null
type
- the Class
designating the Converter
to use; must not be null
null
NullPointerException
- if type
is null
IllegalArgumentException
- if conversion fails because
of a problem with the supplied Value
ConversionException
- 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 null
type
- the TypeLiteral
designating the Converter
to use; must not be null
null
NullPointerException
- if type
is null
IllegalArgumentException
- if conversion fails because
of a problem with the supplied Value
ConversionException
- if conversion fails for any other
reasonnull
.Copyright © 2019–2020, microBean™. All rights reserved.