- All Implemented Interfaces:
Serializable
,Comparable<SimpleType>
,java.lang.constant.Constable
The
SimpleType
enumeration provides functionality useful when working
wit Java's primitive types, their wrapper counterparts as well as with some
other crucial types such as String
, Date
, Enum
,
Class
or Locale
types. This enumeration is the single point
for "simple type" conversion for many other functionality so code is not
scattered around the various libraries disjunct from each other.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionConvert primitive types (e.g.Keep primitive types (e.g.Keep primitive types (e.g.Convert wrapper types (e.g.Convert wrapper types (e.g.Convert primitive types (e.g.Convert primitive types (e.g. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> String
fromSimpleType
(T aValue) Converts a simple type to aString
which can be converted back with the companion methodtoSimpleType(String, Class)
.boolean
Returns true in case primitive type arrays or arrays of their wrappers are supported types.boolean
Returns true in case primitive (array) types are supported types.boolean
Returns true in case wrapper (array) types are supported types.static <T> boolean
invokeSimpleType
(T aToArray, int aToIndex, String aToValue, Class<?> aToType) static <T> boolean
invokeSimpleType
(T aToInstance, Field aToField, String aToValue, Class<?> aToType) static <T> boolean
invokeSimpleType
(T aToInstance, Method aToMethod, String aToValue, Class<?> aToType) static boolean
isCompositeArrayType
(Class<?> aClass) Tests whether the given class represents a composite type array.static boolean
isCompositeType
(Class<?> aClass) Tests whether the given class represents a composite type.static boolean
isCompositeType
(Class<?> aClass, boolean hasArraySupport) Tests whether the given class represents a composite type.static boolean
isPrimitiveArrayType
(Class<?> aClass) Tests whether the given class represents a primitive array type.static boolean
isPrimitiveType
(Class<?> aClass) Tests whether the given class represents a primitive type.static boolean
isPrimitiveType
(Class<?> aClass, boolean hasArraySupport) Tests whether the given class represents a primitive (array) type.static boolean
isSimpleArrayType
(Class<?> aClass) Tests whether the given class represents a simple type array.static boolean
isSimpleType
(Class<?> aClass) Tests whether the given class represents a simple type.static boolean
isSimpleType
(Class<?> aClass, boolean hasArraySupport) Tests whether the given class represents a simple type.static boolean
isWrapperArrayType
(Class<?> aClass) Tests whether the given class represents a wrapper array type of a primitive array type.static boolean
isWrapperType
(Class<?> aClass) Tests whether the given class represents a wrapper type of a primitive type.static boolean
isWrapperType
(Class<?> aClass, boolean hasArraySupport) Tests whether the given class represents a wrapper (array) type.static Class<?>
toPrimitiveType
(Class<?> aClass) Converts the given type to a primitive type if possible and returns the result or null if the given type is not a wrapper type.static Class<?>
toPrimitiveType
(Class<?> aClass, boolean hasArraySupport) Converts the given type to a primitive type if possible and returns the result or null if the given type is not a wrapper type.static <TYPE> TYPE
toSimpleType
(String aValue, Class<TYPE> aType) Converts aString
to a simple type which can be converted back with the companion methodfromSimpleType(Object)
.Class<?>
Converts the passed type as of theSimpleType
.static Class<?>
toWrapperType
(Class<?> aClass) Converts the given type to a wrapper type if possible and returns the result or null if the given type is not a primitive type.static Class<?>
toWrapperType
(Class<?> aClass, boolean hasArraySupport) Converts the given type to a wrapper type if possible and returns the result or null if the given type is not a primitive type.static SimpleType
Returns the enum constant of this type with the specified name.static SimpleType[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
DEFAULT
Convert primitive types (e.g.Byte.TYPE
) to their wrapper types (e.g.Byte
). Array types are converted to non array types with the according array notation (as ofWRAPPER_TYPES
). -
KEEP_TYPES
-
WRAPPER_TYPES
-
PRIMITIVE_TYPES
-
KEEP_TYPES_WITH_ARRAY_TYPES
-
WRAPPER_TYPES_WITH_ARRAY_TYPES
-
PRIMITIVE_TYPES_WITH_ARRAY_TYPES
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
hasPrimitiveTypeSupport
public boolean hasPrimitiveTypeSupport()Returns true in case primitive (array) types are supported types.- Returns:
- True in case primitive (array) types are supported types.
-
hasWrapperTypeSupport
public boolean hasWrapperTypeSupport()Returns true in case wrapper (array) types are supported types.- Returns:
- True in case wrapper (array) types are supported types.
-
hasArrayTypeSupport
public boolean hasArrayTypeSupport()Returns true in case primitive type arrays or arrays of their wrappers are supported types.- Returns:
- True in case primitive type arrays or arrays of their wrappers are supported types.
-
toType
Converts the passed type as of theSimpleType
.- Parameters:
aClass
- The type to be converted.- Returns:
- The converted type.
-
toPrimitiveType
Converts the given type to a primitive type if possible and returns the result or null if the given type is not a wrapper type. Convenience method fortoPrimitiveType(Class, boolean)
without array support.- Parameters:
aClass
- The type to be converted.- Returns:
- The converted type.
-
toPrimitiveType
Converts the given type to a primitive type if possible and returns the result or null if the given type is not a wrapper type.- Parameters:
aClass
- The type to be converted.hasArraySupport
- True in case primitive type arrays or arrays of their wrappers are supported types.- Returns:
- The converted type.
-
toWrapperType
Converts the given type to a wrapper type if possible and returns the result or null if the given type is not a primitive type. Convenience method fortoWrapperType(Class, boolean)
without array support.- Parameters:
aClass
- The type to be converted.- Returns:
- The converted type.
-
toWrapperType
Converts the given type to a wrapper type if possible and returns the result or null if the given type is not a primitive type.- Parameters:
aClass
- The type to be converted.hasArraySupport
- True in case primitive type arrays or arrays of their wrappers are supported types.- Returns:
- The converted type.
-
isPrimitiveType
Tests whether the given class represents a primitive (array) type.- Parameters:
aClass
- The type to be tested.hasArraySupport
- True in case primitive type arrays or arrays of their wrappers are supported types.- Returns:
- True in case of being a primitive type, else false. A return
value of false does not mean that we have a wrapper type (use
isWrapperType(Class)
).
-
isPrimitiveType
Tests whether the given class represents a primitive type.- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a primitive type, else false. A return
value of false does not mean that we have a wrapper type (use
isWrapperType(Class)
).
-
isPrimitiveArrayType
Tests whether the given class represents a primitive array type.- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a primitive array type, else false. A
return value of false does not mean that we have a wrapper array
type (use
isWrapperArrayType(Class)
).
-
isWrapperType
Tests whether the given class represents a wrapper (array) type.- Parameters:
aClass
- The type to be tested.hasArraySupport
- True in case wrapper type arrays or arrays of their wrappers are supported types.- Returns:
- True in case of being a wrapper type, else false. A return value
of false does not mean that we have a wrapper type (use
isWrapperType(Class)
).
-
isWrapperType
Tests whether the given class represents a wrapper type of a primitive type.- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a wrapper type of a primitive type, else
false. A return value of false does not mean that we have a
primitive type (use
isPrimitiveType(Class)
).
-
isWrapperArrayType
Tests whether the given class represents a wrapper array type of a primitive array type.- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a wrapper array type of a primitive array
type, else false. A return value of false does not mean that we
have a primitive array type (use
isPrimitiveArrayType(Class)
).
-
isSimpleType
Tests whether the given class represents a simple type. A simple type is reckoned to be one of the wrapper typesBoolean
,Byte
,Short
,Character
,Integer
,Long
,Float
orDouble
as well as their wrapper types as well as the (not that primitive) typesString
,Enum
andClass
- Parameters:
aClass
- The type to be tested.hasArraySupport
- True in case simple type arrays are supported types.- Returns:
- True in case of being a simple type.
-
isSimpleType
Tests whether the given class represents a simple type. A simple type is reckoned to be one of the wrapper typesBoolean
,Byte
,Short
,Character
,Integer
,Long
,Float
orDouble
as well as their wrapper types as well as the (not that primitive) typesString
,Enum
andClass
- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a simple type.
-
isSimpleArrayType
Tests whether the given class represents a simple type array. A simple type is reckoned to be one of the wrapper typesBoolean
,Byte
,Short
,Character
,Integer
,Long
,Float
orDouble
as well as their wrapper types as well as the (not that primitive) typesString
,Enum
andClass
- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a simple type array.
-
isCompositeType
Tests whether the given class represents a composite type. A composite type is not a simple type (nor a primitive type and neither a wrapper type).- Parameters:
aClass
- The type to be tested.hasArraySupport
- True in case composite type arrays are supported types.- Returns:
- True in case of being a composite type.
-
isCompositeType
Tests whether the given class represents a composite type. A composite type is not a simple type (nor a primitive type and neither a wrapper type).- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a composite type.
-
isCompositeArrayType
Tests whether the given class represents a composite type array. A simple type is reckoned to be one of the wrapper typesBoolean
,Byte
,Short
,Character
,Integer
,Long
,Float
orDouble
as well as their wrapper types as well as the (not that primitive) typesString
,Enum
andClass
- Parameters:
aClass
- The type to be tested.- Returns:
- True in case of being a composite type array.
-
fromSimpleType
Converts a simple type to aString
which can be converted back with the companion methodtoSimpleType(String, Class)
.- Type Parameters:
T
- The simple type's type.- Parameters:
aValue
- The value of the simple type to be converted.- Returns:
- The according
String
or if the value was not a simple type.
-
toSimpleType
Converts aString
to a simple type which can be converted back with the companion methodfromSimpleType(Object)
.- Type Parameters:
TYPE
- the generic type- Parameters:
aValue
- The value to be converted to the simple type.aType
- the a type- Returns:
- The according simple type or null if the type was not a simple type.
-
invokeSimpleType
public static <T> boolean invokeSimpleType(T aToInstance, Method aToMethod, String aToValue, Class<?> aToType) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException Invokes a method with a simple type value'sString
representation, converting theString
instance into the according simple type.- Type Parameters:
T
- The type of the instance on which to do the method invocation.- Parameters:
aToInstance
- The instance on which to invoke the method.aToMethod
- The method to be invoked.aToValue
- TheString
representation of the value to be passed to the method.aToType
- The (simple type) to which the value is to be converted.- Returns:
- True in case a simple type was detected and invocation was done.
False in case the type of the value to be invoked was not a
simple type. See also
isSimpleType(Class)
. - Throws:
NoSuchMethodException
- in case there is none such method for the given instance.IllegalAccessException
- in case method invocation has access restrictions.InvocationTargetException
- in case upon invocation an exceptional situation occurred.InstantiationException
- thrown in case instantiation of required types failed.ClassNotFoundException
- thrown in case a required type's class was not found on the class path.
-
invokeSimpleType
public static <T> boolean invokeSimpleType(T aToInstance, Field aToField, String aToValue, Class<?> aToType) throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException, ClassNotFoundException Invokes a field with a simple type value'sString
representation, converting theString
instance into the according simple type.- Type Parameters:
T
- The type of the instance on which to do the field invocation.- Parameters:
aToInstance
- The instance on which to invoke the field.aToField
- the field to be invoked.aToValue
- TheString
representation of the value to be passed to the field.aToType
- The (simple type) to which the value is to be converted.- Returns:
- True in case a simple type was detected and invocation was done.
False in case the type of the value to be invoked was not a
simple type. See also
isSimpleType(Class)
. - Throws:
NoSuchMethodException
- in case there is none such method for the given instance.IllegalAccessException
- in case method invocation has access restrictions.InstantiationException
- thrown in case instantiation of required types failed.InvocationTargetException
- in case upon invocation an exceptional situation occurred.ClassNotFoundException
- thrown in case a required type's class was not found on the class path.
-
invokeSimpleType
public static <T> boolean invokeSimpleType(T aToArray, int aToIndex, String aToValue, Class<?> aToType) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException Invokes an array at the given index with a simple type value'sString
representation, converting theString
instance into the according simple type.- Type Parameters:
T
- The type of the instance on which to do the array invocation.- Parameters:
aToArray
- the array where to invoke the simple type's value.aToIndex
- the index into the array where to invoke the value to.aToValue
- TheString
representation of the value to be passed to the array.aToType
- The (simple type) to which the value is to be converted.- Returns:
- True in case a simple type was detected and invocation was done.
False in case the type of the value to be invoked was not a
simple type. See also
isSimpleType(Class)
. - Throws:
NoSuchMethodException
- in case there is none such method for the given instance.InstantiationException
- thrown in case instantiation of required types failed.IllegalAccessException
- in case method invocation has access restrictions.InvocationTargetException
- in case upon invocation an exceptional situation occurred.ClassNotFoundException
- thrown in case a required type's class was not found on the class path.
-