Enum Class SimpleType

java.lang.Object
java.lang.Enum<SimpleType>
org.refcodes.struct.SimpleType
All Implemented Interfaces:
Serializable, Comparable<SimpleType>, Constable

public enum SimpleType extends Enum<SimpleType>
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.
  • Enum Constant Details

    • DEFAULT

      public static final SimpleType 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 of WRAPPER_TYPES).
    • KEEP_TYPES

      public static final SimpleType KEEP_TYPES
      Keep primitive types (e.g. Byte.TYPE) as well as their wrapper types (e.g. Byte). Array types are converted to non array types with the according array notation.
    • WRAPPER_TYPES

      public static final SimpleType WRAPPER_TYPES
      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.
    • PRIMITIVE_TYPES

      public static final SimpleType PRIMITIVE_TYPES
      Convert wrapper types (e.g. Byte) to their primitive types (e.g. Byte.TYPE). Array types are converted to non array types with the according array notation.
    • KEEP_TYPES_WITH_ARRAY_TYPES

      public static final SimpleType KEEP_TYPES_WITH_ARRAY_TYPES
      Keep primitive types (e.g. Byte.TYPE) as well as their wrapper types (e.g. Byte). According array types are preserved!
    • WRAPPER_TYPES_WITH_ARRAY_TYPES

      public static final SimpleType WRAPPER_TYPES_WITH_ARRAY_TYPES
      Convert primitive types (e.g. Byte.TYPE) to their wrapper types (e.g. Byte). According array types are preserved!
    • PRIMITIVE_TYPES_WITH_ARRAY_TYPES

      public static final SimpleType PRIMITIVE_TYPES_WITH_ARRAY_TYPES
      Convert wrapper types (e.g. Byte) to their primitive types (e.g. Byte.TYPE). According array types are preserved!
  • Method Details

    • values

      public static SimpleType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SimpleType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified name
      NullPointerException - 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

      public Class<?> toType(Class<?> aClass)
      Converts the passed type as of the SimpleType.
      Parameters:
      aClass - The type to be converted.
      Returns:
      The converted type.
    • toPrimitiveType

      public 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. Convenience method for toPrimitiveType(Class, boolean) without array support.
      Parameters:
      aClass - The type to be converted.
      Returns:
      The converted type.
    • toPrimitiveType

      public 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.
      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

      public 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. Convenience method for toWrapperType(Class, boolean) without array support.
      Parameters:
      aClass - The type to be converted.
      Returns:
      The converted type.
    • toWrapperType

      public 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.
      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

      public static boolean isPrimitiveType(Class<?> aClass, boolean hasArraySupport)
      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

      public static boolean isPrimitiveType(Class<?> aClass)
      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

      public static boolean isPrimitiveArrayType(Class<?> aClass)
      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

      public static boolean isWrapperType(Class<?> aClass, boolean hasArraySupport)
      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

      public static boolean isWrapperType(Class<?> aClass)
      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

      public static boolean isWrapperArrayType(Class<?> aClass)
      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

      public static boolean isSimpleType(Class<?> aClass, boolean hasArraySupport)
      Tests whether the given class represents a simple type. A simple type is reckoned to be one of the wrapper types Boolean, Byte, Short, Character, Integer, Long, Float or Double as well as their wrapper types as well as the (not that primitive) types String, Enum and Class
      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

      public static boolean isSimpleType(Class<?> aClass)
      Tests whether the given class represents a simple type. A simple type is reckoned to be one of the wrapper types Boolean, Byte, Short, Character, Integer, Long, Float or Double as well as their wrapper types as well as the (not that primitive) types String, Enum and Class
      Parameters:
      aClass - The type to be tested.
      Returns:
      True in case of being a simple type.
    • isSimpleArrayType

      public static boolean isSimpleArrayType(Class<?> aClass)
      Tests whether the given class represents a simple type array. A simple type is reckoned to be one of the wrapper types Boolean, Byte, Short, Character, Integer, Long, Float or Double as well as their wrapper types as well as the (not that primitive) types String, Enum and Class
      Parameters:
      aClass - The type to be tested.
      Returns:
      True in case of being a simple type array.
    • isCompositeType

      public static boolean isCompositeType(Class<?> aClass, boolean hasArraySupport)
      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

      public static boolean isCompositeType(Class<?> aClass)
      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

      public static boolean isCompositeArrayType(Class<?> aClass)
      Tests whether the given class represents a composite type array. A simple type is reckoned to be one of the wrapper types Boolean, Byte, Short, Character, Integer, Long, Float or Double as well as their wrapper types as well as the (not that primitive) types String, Enum and Class
      Parameters:
      aClass - The type to be tested.
      Returns:
      True in case of being a composite type array.
    • fromSimpleType

      public static <T> String fromSimpleType(T aValue)
      Converts a simple type to a String which can be converted back with the companion method toSimpleType(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

      public static <TYPE> TYPE toSimpleType(String aValue, Class<TYPE> aType)
      Converts a String to a simple type which can be converted back with the companion method fromSimpleType(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's String representation, converting the String 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 - The String 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's String representation, converting the String 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 - The String 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's String representation, converting the String 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 - The String 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.