org.chromattic.common
Class ValueType<T>

java.lang.Object
  extended by org.chromattic.common.ValueType<T>
Type Parameters:
T - the value java type

public abstract class ValueType<T>
extends java.lang.Object

The enumeration of value type that are permitted for attributes state. The generic type is used to represent the relevant associated java type for the runtime values.

Version:
$Revision$
Author:
Julien Viet

Field Summary
static ValueType<java.lang.Boolean> BOOLEAN
          .
static ValueType<java.util.Date> DATE
          .
static ValueType<java.lang.Double> DOUBLE
          .
static ValueType<java.lang.Integer> INTEGER
          .
static ValueType<java.lang.String> STRING
          .
 
Method Summary
 T cast(java.lang.Object o)
          Casts the object to the underlying java type.
static
<T> ValueType<T>
decode(T t)
          Returns the corresponding value type for the specified object or null if no valid one can be found.
static
<T> ValueType<T>
forClass(java.lang.Class<T> t)
          Returns the corresponding value type for the specified java class.
static
<T> ValueType<T>
get(T t)
          Returns the corresponding value type for the specified object.
 java.lang.Class<T> getJavaType()
          Returns the java type.
 boolean isInstance(java.lang.Object o)
          Returns true if the object matches the type.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING

public static final ValueType<java.lang.String> STRING
.


INTEGER

public static final ValueType<java.lang.Integer> INTEGER
.


BOOLEAN

public static final ValueType<java.lang.Boolean> BOOLEAN
.


DATE

public static final ValueType<java.util.Date> DATE
.


DOUBLE

public static final ValueType<java.lang.Double> DOUBLE
.

Method Detail

getJavaType

public java.lang.Class<T> getJavaType()
Returns the java type.

Returns:
the java type

isInstance

public boolean isInstance(java.lang.Object o)
Returns true if the object matches the type.

Parameters:
o - the object
Returns:
true when the value matches the type

cast

public T cast(java.lang.Object o)
       throws java.lang.ClassCastException
Casts the object to the underlying java type.

Parameters:
o - the object to cast
Returns:
the casted object
Throws:
java.lang.ClassCastException - if the object cannot be casted

decode

public static <T> ValueType<T> decode(T t)
Returns the corresponding value type for the specified object or null if no valid one can be found.

Type Parameters:
T - the java type
Parameters:
t - the object to decode type for
Returns:
the decoded type

get

public static <T> ValueType<T> get(T t)
                        throws java.lang.NullPointerException,
                               java.lang.IllegalArgumentException
Returns the corresponding value type for the specified object.

Type Parameters:
T - the java type
Parameters:
t - the object to get the type for
Returns:
the decoded type
Throws:
java.lang.NullPointerException - if the argument is null
java.lang.IllegalArgumentException - if the argument does not match a valid type

forClass

public static <T> ValueType<T> forClass(java.lang.Class<T> t)
                             throws java.lang.NullPointerException,
                                    java.lang.IllegalArgumentException
Returns the corresponding value type for the specified java class.

Type Parameters:
T - the java type
Parameters:
t - the java type
Returns:
the decoded type
Throws:
java.lang.NullPointerException - if the argument is null
java.lang.IllegalArgumentException - if the argument does not match a valid type

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2011 eXo Platform SAS. All Rights Reserved.