Package jodd.typeconverter.impl
Class ArrayConverter<T>
- java.lang.Object
-
- jodd.typeconverter.impl.ArrayConverter<T>
-
- All Implemented Interfaces:
TypeConverter<T[]>
- Direct Known Subclasses:
ClassArrayConverter,StringArrayConverter
public class ArrayConverter<T> extends java.lang.Object implements TypeConverter<T[]>
Converts given object to an array. This converter is specific, as it is not directly registered to a type; but created when needed. Conversion rules:nullvalue is returned asnull- source non-array value is checked for
Collections - if non-array element can't be resolved, it is converted to single element array
- source array is converted to target array, by converting each element
-
-
Field Summary
Fields Modifier and Type Field Description static char[]NUMBER_DELIMITERSprotected java.lang.Class<T>targetComponentTypeprotected TypeConverterManagertypeConverterManager
-
Constructor Summary
Constructors Constructor Description ArrayConverter(TypeConverterManager typeConverterManager, java.lang.Class<T> targetComponentType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T[]convert(java.lang.Object value)Converts object received as parameter into object of another class.protected T[]convertArrayToArray(java.lang.Object value)Converts array value to array.protected T[]convertPrimitiveArrayToArray(java.lang.Object value, java.lang.Class primitiveComponentType)Converts primitive array to target array.protected java.lang.String[]convertStringToArray(java.lang.String value)Converts string to array, for theconvertValueToArray(Object)method.protected T[]convertToSingleElementArray(java.lang.Object value)Creates an array with single element.protected TconvertType(java.lang.Object value)Converts type using type converter manager.protected T[]convertValueToArray(java.lang.Object value)Converts non-array value to array.protected T[]createArray(int length)Creates new array of target component type.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jodd.typeconverter.TypeConverter
convert
-
-
-
-
Field Detail
-
NUMBER_DELIMITERS
public static final char[] NUMBER_DELIMITERS
-
typeConverterManager
protected final TypeConverterManager typeConverterManager
-
targetComponentType
protected final java.lang.Class<T> targetComponentType
-
-
Constructor Detail
-
ArrayConverter
public ArrayConverter(TypeConverterManager typeConverterManager, java.lang.Class<T> targetComponentType)
-
-
Method Detail
-
convert
public T[] convert(java.lang.Object value)
Description copied from interface:TypeConverterConverts object received as parameter into object of another class. For example, anIntegerconverter tries to convert given objects into targetIntegerobject. Converters should try all reasonable ways of conversion into target object, depending on target type.- Specified by:
convertin interfaceTypeConverter<T>- Parameters:
value- object to convert from- Returns:
- resulting object converted to target type
-
convertType
protected T convertType(java.lang.Object value)
Converts type using type converter manager.
-
createArray
protected T[] createArray(int length)
Creates new array of target component type. Default implementation uses reflection to create an array of target type. Override it for better performances.
-
convertToSingleElementArray
protected T[] convertToSingleElementArray(java.lang.Object value)
Creates an array with single element.
-
convertValueToArray
protected T[] convertValueToArray(java.lang.Object value)
Converts non-array value to array. Detects various collection types and iterates them to make conversion and to create target array.
-
convertStringToArray
protected java.lang.String[] convertStringToArray(java.lang.String value)
Converts string to array, for theconvertValueToArray(Object)method. By default, the string is converted into an array usingCsvUtil.
-
convertArrayToArray
protected T[] convertArrayToArray(java.lang.Object value)
Converts array value to array.
-
convertPrimitiveArrayToArray
protected T[] convertPrimitiveArrayToArray(java.lang.Object value, java.lang.Class primitiveComponentType)
Converts primitive array to target array.
-
-