Package com.gengoai.conversion
Class Val
- java.lang.Object
-
- com.gengoai.conversion.Val
-
- All Implemented Interfaces:
Serializable
public class Val extends Object implements Serializable
Wraps an object allowing conversion into other formats.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
as(Class<T> clazz)
Converts the underlying object to the given class type.<T> T
as(Class<T> clazz, T defaultValue)
Converts the underlying object to the given class type.<T> T
as(Type type)
As t.<T> T
as(Type type, T defaultValue)
As t.<T> T[]
asArray(Class<T> clazz)
Converts an object into an array of objects<T> T[]
asArray(Type componentType)
As array t [ ].Boolean
asBoolean()
As boolean.Boolean
asBoolean(Boolean defaultValue)
As boolean.Boolean[]
asBooleanArray()
As boolean array.boolean
asBooleanValue()
As boolean value.boolean
asBooleanValue(boolean defaultValue)
As boolean value.boolean[]
asBooleanValueArray()
As boolean value array.Byte
asByte()
As byte.Byte
asByte(Byte defaultValue)
As byte.Byte[]
asByteArray()
As byte array.byte
asByteValue()
As byte value.byte
asByteValue(byte defaultValue)
As byte value.byte[]
asByteValueArray()
As byte value array.Character
asCharacter()
As character.Character
asCharacter(Character defaultValue)
As character.Character[]
asCharacterArray()
As character array.char
asCharacterValue()
As character value.char
asCharacterValue(char defaultValue)
As character value.char[]
asCharacterValueArray()
As character value array.Class<?>
asClass()
As class.<T> Class<T>
asClass(Class<T> defaultValue)
As class.Double
asDouble()
As double.Double
asDouble(Double defaultValue)
As double.Double[]
asDoubleArray()
As double array.double
asDoubleValue()
As double value.double
asDoubleValue(double defaultValue)
As double value.double[]
asDoubleValueArray()
As double value array.Float
asFloat()
As float.Float
asFloat(Float defaultValue)
As float.Float[]
asFloatArray()
As float array.float
asFloatValue()
As float value.float
asFloatValue(float defaultValue)
As float value.float[]
asFloatValueArray()
As float value array.Integer
asInteger()
As integer.Integer
asInteger(Integer defaultValue)
As integer.Integer[]
asIntegerArray()
As integer array.int
asIntegerValue()
As integer value.int
asIntegerValue(int defaultValue)
As integer value.int[]
asIntegerValueArray()
As integer value array.<T> List<T>
asList(Class<T> itemType)
Converts the object to a List<T> List<T>
asList(Type itemType)
Long
asLong()
As long.Long
asLong(Long defaultValue)
As long.Long[]
asLongArray()
As long array.long
asLongValue()
As long value.long
asLongValue(long defaultValue)
As long value.long[]
asLongValueArray()
As long value array.<K,V>
Map<K,V>asMap(Class<K> keyClass, Class<V> valueClass)
Converts the object to a mapResource
asResource()
Converts the object to resourceResource
asResource(Resource defaultResource)
Converts the object to resource with a given default if the conversion results in a null value.<T> Set<T>
asSet(Class<T> itemType)
Converts the object to a Set<T> Set<T>
asSet(Type itemType)
Short
asShort()
As short.Short
asShort(Short defaultValue)
As short.Short[]
asShortArray()
As short array.short
asShortValue()
As short value.short
asShortValue(short defaultValue)
As short value.short[]
asShortValueArray()
As short value array.String
asString()
As string.String
asString(String defaultValue)
As string.<T> T
cast()
Casts the objectboolean
equals(Object o)
Object
get()
Get object.Class<?>
getWrappedClass()
Get wrapped class.boolean
isArray()
Determines if the wrapped object is an arrayboolean
isCollection()
Determines if the wrapped object is a Collectionboolean
isIterable()
Determines if the wrapped object is an Iterableboolean
isIterator()
Determines if the wrapped object is an Iteratorboolean
isMap()
Determines if the wrapped object is a Mapboolean
isNull()
Is null.boolean
isPrimitiveArray()
Determines if the wrapped object is a primitive arraystatic Val
of(Object o)
Convenience method for creating a Convertible ObjectString
toString()
-
-
-
Constructor Detail
-
Val
protected Val(Object toConvert)
Default Constructor- Parameters:
toConvert
- The object to convert
-
-
Method Detail
-
of
public static Val of(Object o)
Convenience method for creating a Convertible Object- Parameters:
o
- The object to convert- Returns:
- The ConvertibleObject wrapping the given object
-
as
public <T> T as(Type type)
As t.- Type Parameters:
T
- the type parameter- Parameters:
type
- the type- Returns:
- the t
-
as
public <T> T as(Type type, T defaultValue)
As t.- Type Parameters:
T
- the type parameter- Parameters:
type
- the typedefaultValue
- the default value- Returns:
- the t
-
as
public <T> T as(Class<T> clazz)
Converts the underlying object to the given class type.- Type Parameters:
T
- the type parameter- Parameters:
clazz
- The class to convert to- Returns:
- This object as the given type or null if the wrapped object is null
-
as
public <T> T as(Class<T> clazz, T defaultValue)
Converts the underlying object to the given class type.- Type Parameters:
T
- the type parameter- Parameters:
clazz
- The class to convert todefaultValue
- The value to return if the wrapped value is null or cannot be converted- Returns:
- This object as the given type or null if the wrapped object is null
-
asArray
public <T> T[] asArray(Type componentType)
As array t [ ].- Type Parameters:
T
- the type parameter- Parameters:
componentType
- the component type- Returns:
- the t [ ]
-
asArray
public <T> T[] asArray(Class<T> clazz)
Converts an object into an array of objects- Type Parameters:
T
- the type parameter- Parameters:
clazz
- The type of the object to create.- Returns:
- An array of the object
-
asBoolean
public Boolean asBoolean()
As boolean.- Returns:
- the object as a Boolean.
-
asBoolean
public Boolean asBoolean(Boolean defaultValue)
As boolean.- Parameters:
defaultValue
- the default value- Returns:
- the object as a Boolean.
-
asBooleanArray
public Boolean[] asBooleanArray()
As boolean array.- Returns:
- the object as a Boolean array.
-
asBooleanValue
public boolean asBooleanValue()
As boolean value.- Returns:
- the object as a boolean.
-
asBooleanValue
public boolean asBooleanValue(boolean defaultValue)
As boolean value.- Parameters:
defaultValue
- the default value- Returns:
- the object as a boolean.
-
asBooleanValueArray
public boolean[] asBooleanValueArray()
As boolean value array.- Returns:
- the object as a boolean array.
-
asByte
public Byte asByte()
As byte.- Returns:
- the object as a Byte.
-
asByte
public Byte asByte(Byte defaultValue)
As byte.- Parameters:
defaultValue
- the default value- Returns:
- the object as a Byte.
-
asByteArray
public Byte[] asByteArray()
As byte array.- Returns:
- the object as a Byte array.
-
asByteValue
public byte asByteValue()
As byte value.- Returns:
- the object as a byte.
-
asByteValue
public byte asByteValue(byte defaultValue)
As byte value.- Parameters:
defaultValue
- the default value- Returns:
- the object as a byte.
-
asByteValueArray
public byte[] asByteValueArray()
As byte value array.- Returns:
- the object as a byte array.
-
asCharacter
public Character asCharacter()
As character.- Returns:
- The object as a Character
-
asCharacter
public Character asCharacter(Character defaultValue)
As character.- Parameters:
defaultValue
- The default value- Returns:
- The object as a char
-
asCharacterArray
public Character[] asCharacterArray()
As character array.- Returns:
- The object as a Character array
-
asCharacterValue
public char asCharacterValue()
As character value.- Returns:
- The object as a char
-
asCharacterValue
public char asCharacterValue(char defaultValue)
As character value.- Parameters:
defaultValue
- The default value- Returns:
- The object as a char
-
asCharacterValueArray
public char[] asCharacterValueArray()
As character value array.- Returns:
- The object as a char array
-
asClass
public Class<?> asClass()
As class.- Returns:
- the object as a class
-
asClass
public <T> Class<T> asClass(Class<T> defaultValue)
As class.- Type Parameters:
T
- the type parameter- Parameters:
defaultValue
- the default value- Returns:
- The object as a class
-
asDouble
public Double asDouble()
As double.- Returns:
- The object as a Double
-
asDouble
public Double asDouble(Double defaultValue)
As double.- Parameters:
defaultValue
- The default value- Returns:
- The object as a double
-
asDoubleArray
public Double[] asDoubleArray()
As double array.- Returns:
- The object as a Double array
-
asDoubleValue
public double asDoubleValue()
As double value.- Returns:
- The object as a double
-
asDoubleValue
public double asDoubleValue(double defaultValue)
As double value.- Parameters:
defaultValue
- The default value- Returns:
- The object as a double
-
asDoubleValueArray
public double[] asDoubleValueArray()
As double value array.- Returns:
- The object as a double array
-
asFloat
public Float asFloat()
As float.- Returns:
- The object as a Float
-
asFloat
public Float asFloat(Float defaultValue)
As float.- Parameters:
defaultValue
- The default value- Returns:
- The object as a float
-
asFloatArray
public Float[] asFloatArray()
As float array.- Returns:
- The object as a Float array
-
asFloatValue
public float asFloatValue()
As float value.- Returns:
- The object as a float
-
asFloatValue
public float asFloatValue(float defaultValue)
As float value.- Parameters:
defaultValue
- The default value- Returns:
- The object as a float
-
asFloatValueArray
public float[] asFloatValueArray()
As float value array.- Returns:
- The object as a float array
-
asInteger
public Integer asInteger()
As integer.- Returns:
- The object as a Integer
-
asInteger
public Integer asInteger(Integer defaultValue)
As integer.- Parameters:
defaultValue
- The default value- Returns:
- The object as a int
-
asIntegerArray
public Integer[] asIntegerArray()
As integer array.- Returns:
- The object as a Integer array
-
asIntegerValue
public int asIntegerValue()
As integer value.- Returns:
- The object as a int
-
asIntegerValue
public int asIntegerValue(int defaultValue)
As integer value.- Parameters:
defaultValue
- The default value- Returns:
- The object as a int
-
asIntegerValueArray
public int[] asIntegerValueArray()
As integer value array.- Returns:
- The object as a int array
-
asList
public <T> List<T> asList(Class<T> itemType)
Converts the object to a List- Type Parameters:
T
- the type parameter- Parameters:
itemType
- The class of the item in the List- Returns:
- The object as a List
-
asLong
public Long asLong()
As long.- Returns:
- The object as a Long
-
asLong
public Long asLong(Long defaultValue)
As long.- Parameters:
defaultValue
- The default value- Returns:
- The object as a long
-
asLongArray
public Long[] asLongArray()
As long array.- Returns:
- The object as a Long array
-
asLongValue
public long asLongValue()
As long value.- Returns:
- The object as a long
-
asLongValue
public long asLongValue(long defaultValue)
As long value.- Parameters:
defaultValue
- The default value- Returns:
- The object as a long
-
asLongValueArray
public long[] asLongValueArray()
As long value array.- Returns:
- The object as a long array
-
asMap
public <K,V> Map<K,V> asMap(Class<K> keyClass, Class<V> valueClass)
Converts the object to a map- Type Parameters:
K
- the type parameterV
- the type parameter- Parameters:
keyClass
- The key classvalueClass
- The value class- Returns:
- the object as a map
-
asResource
public Resource asResource()
Converts the object to resource- Returns:
- The object as a Resource
-
asResource
public Resource asResource(Resource defaultResource)
Converts the object to resource with a given default if the conversion results in a null value.- Parameters:
defaultResource
- The default value when conversion results in null- Returns:
- The value as a resource or
defaultResource
if null
-
asSet
public <T> Set<T> asSet(Class<T> itemType)
Converts the object to a Set- Type Parameters:
T
- the type parameter- Parameters:
itemType
- The class of the item in the Set- Returns:
- The object as a Set
-
asShort
public Short asShort()
As short.- Returns:
- The object as a Short
-
asShort
public Short asShort(Short defaultValue)
As short.- Parameters:
defaultValue
- The default value- Returns:
- The object as a short
-
asShortArray
public Short[] asShortArray()
As short array.- Returns:
- The object as a Short array
-
asShortValue
public short asShortValue()
As short value.- Returns:
- The object as a short
-
asShortValue
public short asShortValue(short defaultValue)
As short value.- Parameters:
defaultValue
- The default value- Returns:
- The object as a short
-
asShortValueArray
public short[] asShortValueArray()
As short value array.- Returns:
- The object as a short array
-
asString
public String asString()
As string.- Returns:
- the object as a string
-
asString
public String asString(String defaultValue)
As string.- Parameters:
defaultValue
- The default value- Returns:
- the object as a string
-
cast
public <T> T cast()
Casts the object- Type Parameters:
T
- the type of the class- Returns:
- the object cast as the class type
-
get
public Object get()
Get object.- Returns:
- The wrapped object
-
getWrappedClass
public Class<?> getWrappedClass()
Get wrapped class.- Returns:
- the class
-
isArray
public boolean isArray()
Determines if the wrapped object is an array- Returns:
- True if it the wrapped object is an array
-
isCollection
public boolean isCollection()
Determines if the wrapped object is a Collection- Returns:
- True if it the wrapped object is a Collection
-
isIterable
public boolean isIterable()
Determines if the wrapped object is an Iterable- Returns:
- True if it the wrapped object is an Iterable
-
isIterator
public boolean isIterator()
Determines if the wrapped object is an Iterator- Returns:
- True if it the wrapped object is an Iterator
-
isMap
public boolean isMap()
Determines if the wrapped object is a Map- Returns:
- True if it the wrapped object is a Map
-
isNull
public boolean isNull()
Is null.- Returns:
- True if the object to convert is null
-
isPrimitiveArray
public boolean isPrimitiveArray()
Determines if the wrapped object is a primitive array- Returns:
- True if it the wrapped object is a primitive array
-
-