Class Converter
- java.lang.Object
-
- com.norconex.commons.lang.convert.Converter
-
- All Implemented Interfaces:
IConverter
public final class Converter extends Object implements IConverter
Converts strings to objects and objects to strings. Supported object types are guaranteed to be convertibles both ways if converted by this class.
Can only be initialized at construction time or the default instance can be obtained statically.
Converted string values are NOT locale-specific. This class favors consistency over format and string values are not always appropriate for human-consumption.
Default instance has converters for the following types:
Byte/byteShort/shortInteger/intFloat/floatLong/longDouble/doubleBigIntegerBigDecimalBoolean/booleanCharacter/charFilePathDateLocalDateTimeZonedDateTimeInstantLocaleEnumDimensionDurationContentTypeCharsetURL
By default
ConverterExceptionis thrown when conversion fails.- Since:
- 2.0.0
- Author:
- Pascal Essiembre
- See Also:
ConverterException
-
-
Constructor Summary
Constructors Constructor Description Converter(Map<Class<?>,IConverter> converters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Stringconvert(Object object)static Stringconvert(Object object, String defaultValue)static <T> Tconvert(String value, Class<T> type)static <T> Tconvert(String value, Class<T> type, T defaultValue)static List<String>convert(List<Object> objects)static <T> List<T>convert(List<String> values, Class<T> type)static ConverterdefaultInstance()IConvertergetConverter(Class<?> type)Map<Class<?>,IConverter>getConverters()booleanisConvertible(Class<?> type)StringtoString(Object object)StringtoString(Object object, String defaultValue)List<String>toString(List<?> objects)<T> TtoType(String value, Class<T> type)<T> TtoType(String value, Class<T> type, T defaultValue)<T> List<T>toType(List<String> values, Class<T> type)
-
-
-
Constructor Detail
-
Converter
public Converter(Map<Class<?>,IConverter> converters)
-
-
Method Detail
-
defaultInstance
public static Converter defaultInstance()
-
getConverters
public Map<Class<?>,IConverter> getConverters()
-
toType
public <T> T toType(String value, Class<T> type)
- Specified by:
toTypein interfaceIConverter
-
toType
public <T> T toType(String value, Class<T> type, T defaultValue)
- Specified by:
toTypein interfaceIConverter
-
toString
public String toString(Object object)
- Specified by:
toStringin interfaceIConverter
-
toString
public String toString(Object object, String defaultValue)
- Specified by:
toStringin interfaceIConverter
-
isConvertible
public boolean isConvertible(Class<?> type)
-
getConverter
public IConverter getConverter(Class<?> type)
-
-