public class ConversionHub extends Object implements Closeable, Serializable, TypeConverter
convert(String, Type),
Serialized Form| Constructor and Description |
|---|
ConversionHub()
Creates a new
ConversionHub. |
ConversionHub(Map<? extends Type,? extends Converter<?>> converters)
Creates a new
ConversionHub. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this
ConversionHub using a best-effort strategy. |
<T> T |
convert(String value,
Type type)
Attempts to convert the supplied
String value to an
object assignable to the supplied Type, throwing an
IllegalArgumentException if such conversion is
impossible. |
boolean |
isClosed()
|
public ConversionHub()
ConversionHub.public ConversionHub(Map<? extends Type,? extends Converter<?>> converters)
ConversionHub.
converters will be synchronized on and iterated
over by this constructor, which may have implications on
the type of Map supplied.
converters - a Map of Converter instances,
indexed by the Type describing the type of the return
value of their respective Converter.convert(String)
methods; may be null; will be synchronized on and
iterated over; copied by value; no reference is kept to
this objectpublic void close() throws IOException
ConversionHub using a best-effort strategy.
This method attempts to close each of this ConversionHub's associated Closeable Converters.
Any IOException thrown during such an attempt does not
abort the closing process.
Once this method has been invoked:
convert(String, Type)
method will throw an IllegalStateExceptionisClosed() method will
return trueConversionHub instances are often supplied to
Config instances at construction time, and so may
be closed by them.
This method is safe for concurrent use by multiple threads.
close in interface Closeableclose in interface AutoCloseableIOException - if at least one underlying Closeable Converter could not be closedpublic final boolean isClosed()
true if this ConversionHub has been
closed.
All invocations of the convert(String, Type) method
will always throw an IllegalStateException once this
ConversionHub has been closed.
This method is idempotent and safe for concurrent use by multiple threads.
true if this ConversionHub has been
closed; false otherwiseclose()public final <T> T convert(String value, Type type)
String value to an
object assignable to the supplied Type, throwing an
IllegalArgumentException if such conversion is
impossible.
This method may return null.
This method is safe for concurrent use by multiple threads.
convert in interface TypeConverterT - the type of the return value, assumed to be assignable
to references of the supplied typevalue - the value to convert; may be nulltype - the Type to which the value should be
converted; must not be null; the type of the return value
resulting from invocations this method should be assignable to
references of this typenullIllegalArgumentException - if conversion could not occur
for any reasonIllegalStateException - if this ConversionHub
was closedCopyright © 2019–2021, microBean™. All rights reserved.