Enum Type

  • All Implemented Interfaces:
    Serializable, Comparable<Type>

    public enum Type
    extends Enum<Type>
    Generic representation of a type.
    allowAssignmentFrom accepts any class, but Array.class means that the type accepts generic Arrays.
    Author:
    Luca Garulli (l.garulli--(at)--gmail.com)
    • Enum Constant Detail

      • BOOLEAN

        public static final Type BOOLEAN
      • INTEGER

        public static final Type INTEGER
      • SHORT

        public static final Type SHORT
      • LONG

        public static final Type LONG
      • FLOAT

        public static final Type FLOAT
      • DOUBLE

        public static final Type DOUBLE
      • DATETIME

        public static final Type DATETIME
      • STRING

        public static final Type STRING
      • BINARY

        public static final Type BINARY
      • LIST

        public static final Type LIST
      • MAP

        public static final Type MAP
      • LINK

        public static final Type LINK
      • BYTE

        public static final Type BYTE
      • DATE

        public static final Type DATE
      • DECIMAL

        public static final Type DECIMAL
      • EMBEDDED

        public static final Type EMBEDDED
    • Field Detail

      • name

        protected final String name
      • id

        protected final int id
      • binaryType

        protected final byte binaryType
      • javaDefaultType

        protected final Class<?> javaDefaultType
      • allowAssignmentFrom

        protected final Class<?>[] allowAssignmentFrom
      • castable

        protected final Set<Type> castable
    • Method Detail

      • values

        public static Type[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Type c : Type.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static Type valueOf​(String name)
        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 name
        NullPointerException - if the argument is null
      • getById

        public static Type getById​(byte iId)
        Return the type by ID.
        Parameters:
        iId - The id to search
        Returns:
        The type if any, otherwise null
      • validateValue

        public static void validateValue​(Object value)
      • getId

        public int getId()
        Get the identifier of the type. use this instead of Enum.ordinal() for guarantee a cross code version identifier.
        Returns:
        the identifier of the type.
      • getTypeByClass

        public static Type getTypeByClass​(Class<?> iClass)
        Return the correspondent type by checking the "assignability" of the class received as parameter.
        Parameters:
        iClass - Class to check
        Returns:
        OType instance if found, otherwise null
      • getTypeByValue

        public static Type getTypeByValue​(Object value)
      • getTypeByName

        public static Type getTypeByName​(String name)
      • isSimpleType

        public static boolean isSimpleType​(Object iObject)
      • convert

        public static Object convert​(Database database,
                                     Object iValue,
                                     Class<?> iTargetClass)
        Convert types based on the iTargetClass parameter.
        Parameters:
        iValue - Value to convert
        iTargetClass - Expected class
        Returns:
        The converted value or the original if no conversion was applied
      • castComparableNumber

        public static Number[] castComparableNumber​(Number context,
                                                    Number max)
      • asInt

        public int asInt​(Object iValue)
        Convert the input object to an integer.
        Parameters:
        iValue - Any type supported
        Returns:
        The integer value if the conversion succeed, otherwise the IllegalArgumentException exception
      • asLong

        public long asLong​(Object iValue)
        Convert the input object to a long.
        Parameters:
        iValue - Any type supported
        Returns:
        The long value if the conversion succeed, otherwise the IllegalArgumentException exception
      • asFloat

        public float asFloat​(Object iValue)
        Convert the input object to a Float.
        Parameters:
        iValue - Any type supported
        Returns:
        The float value if the conversion succeed, otherwise the IllegalArgumentException exception
      • asDouble

        public double asDouble​(Object iValue)
        Convert the input object to a Double.
        Parameters:
        iValue - Any type supported
        Returns:
        The double value if the conversion succeed, otherwise the IllegalArgumentException exception
      • getBinaryType

        public byte getBinaryType()
      • asString

        @Deprecated
        public String asString​(Object iValue)
        Deprecated.
        Convert the input object to a string.
        Parameters:
        iValue - Any type supported
        Returns:
        The string if the conversion succeed, otherwise the IllegalArgumentException exception
      • isMultiValue

        public boolean isMultiValue()
      • isLink

        public boolean isLink()
      • isEmbedded

        public boolean isEmbedded()
      • getDefaultJavaType

        public Class<?> getDefaultJavaType()
      • getCastable

        public Set<Type> getCastable()