Last update: 2011-06-23

org.proteios.core
Enum Type

java.lang.Object
  extended by java.lang.Enum<Type>
      extended by org.proteios.core.Type
All Implemented Interfaces:
Serializable, Comparable<Type>

public enum Type
extends Enum<Type>

This class defines constants for supported value types in Proteios.

Version:
2.0
Author:
Samuel, Nicklas
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Enum Constant Summary
BOOLEAN
          Boolean type.
DATE
          The parameter is a date value.
DOUBLE
          Double type.
FLOAT
          Float type.
INT
          Integer type.
LONG
          Long integer type.
STRING
          String type where maximum length allowed is 255 characters.
TEXT
          Text blob type.
 
Method Summary
 boolean canEnumerate()
          If it makes sense to use values of this type as an enumeration to choose from.
static Type fromValue(int value)
          Get the Type object when you know the integer code.
static Type fromValue(String value)
          Get the Type object when you know the string value.
 org.hibernate.type.NullableType getHibernateType()
          Get the hibernate type of this parameter
 int getSQLType()
          Get the type of this parameter as specified by the java.sql.Types class.
 String getStringValue()
          Get the string value representation of this type.
 int getValue()
          Get the integer value that is used when storing a type in the database.
 Class<?> getValueClass()
          Get the class of objects that can be used as values for this type.
 boolean isCorrectType(Object value)
          Check if the value is an object of the correct type.
 boolean isNumerical()
          If the values of this type are numerical values.
 Object parseString(String value)
          Parse a string and return a value of the correct type.
 Object[] parseStrings(String[] values)
          Parse an array of strings and try to convert them to values of the correct object type.
abstract  int sizeOf(Object value)
          Get the size in bytes an object of this type requires when stored in the database.
 String toString()
           
 void validate(List<?> values)
          Check if a list of values contain only objects of the correct type.
 void validate(Object value)
          Check if an object is a value of the correct type.
static Type valueOf(String name)
          Returns the enum constant of this type with the specified name.
static Type[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

INT

public static final Type INT
Integer type.


LONG

public static final Type LONG
Long integer type.


FLOAT

public static final Type FLOAT
Float type.


DOUBLE

public static final Type DOUBLE
Double type.


STRING

public static final Type STRING
String type where maximum length allowed is 255 characters.

See Also:
TEXT

TEXT

public static final Type TEXT
Text blob type.

See Also:
STRING

BOOLEAN

public static final Type BOOLEAN
Boolean type.


DATE

public static final Type DATE
The parameter is a date value.

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

toString

public String toString()
Overrides:
toString in class Enum<Type>

getHibernateType

public org.hibernate.type.NullableType getHibernateType()
Get the hibernate type of this parameter

Returns:
The hibernate type of the parameter

getValue

public int getValue()
Get the integer value that is used when storing a type in the database.


getValueClass

public Class<?> getValueClass()
Get the class of objects that can be used as values for this type.

See Also:
isCorrectType(Object)

getStringValue

public String getStringValue()
Get the string value representation of this type.


getSQLType

public int getSQLType()
Get the type of this parameter as specified by the java.sql.Types class.

Returns:
The type-code of the parameter

canEnumerate

public boolean canEnumerate()
If it makes sense to use values of this type as an enumeration to choose from. For example, the BOOLEAN and TEXT type can't be enumerated.


isNumerical

public boolean isNumerical()
If the values of this type are numerical values.

Returns:
TRUE if the values are numerical, FALSE otherwise

validate

public void validate(Object value)
              throws InvalidDataException
Check if an object is a value of the correct type. Null is allowed.

Throws:
InvalidDataException - If the value isn't of the correct type

validate

public void validate(List<?> values)
              throws InvalidDataException
Check if a list of values contain only objects of the correct type.

Throws:
InvalidDataException - If the list contains one or more nulls or values of incorrect object type

isCorrectType

public boolean isCorrectType(Object value)
Check if the value is an object of the correct type.


sizeOf

public abstract int sizeOf(Object value)
Get the size in bytes an object of this type requires when stored in the database. If the value if null, 0 is returned, otherwise the actual value is only used if it affects the size, ie. it is a string.

Parameters:
value - The value to get the size of

parseString

public Object parseString(String value)
                   throws InvalidDataException
Parse a string and return a value of the correct type.

Throws:
InvalidDataException

parseStrings

public Object[] parseStrings(String[] values)
                      throws InvalidDataException
Parse an array of strings and try to convert them to values of the correct object type.

Returns:
An array of objects, or null of the array is null
Throws:
InvalidDataException - If at least one of the strings could not be parsed to the correct type

fromValue

public static Type fromValue(int value)
Get the Type object when you know the integer code.


fromValue

public static Type fromValue(String value)
Get the Type object when you know the string value.


Last update: 2011-06-23