com.google.api.client.util
Class FieldInfo

java.lang.Object
  extended by com.google.api.client.util.FieldInfo

public class FieldInfo
extends Object

Parses field information to determine data key name/value pair associated with the field.

Since:
1.0
Author:
Yaniv Inbar

Field Summary
 Field field
          Deprecated. (scheduled to be made private in 1.5) Use getField()
 boolean isFinal
          Deprecated. (scheduled to be removed in 1.5) Use isFinal()
 boolean isPrimitive
          Deprecated. (scheduled to be made private in 1.5) Use isPrimitive()
 String name
          Deprecated. (scheduled to be made private in 1.5) Use getName()
 Class<?> type
          Deprecated. (scheduled to be removed in 1.5) Use getType()
 
Method Summary
<T extends Enum<T>>
T
enumValue()
           
 ClassInfo getClassInfo()
          Returns the class information of the field's declaring class.
 Field getField()
          Returns the field.
static Object getFieldValue(Field field, Object obj)
          Returns the value of the given field in the given object instance using reflection.
 Type getGenericType()
          Returns the field's generic type, which is a class, parameterized type, generic array type, or type variable, but not a wildcard type.
 String getName()
          Returns the data key name associated with the field for a non-enum-constant with a Key annotation, or data key value associated with the enum constant with a Value annotation or null for an enum constant with a NullValue annotation.
 Class<?> getType()
          Returns the field's type.
 Object getValue(Object obj)
          Returns the value of the field in the given object instance using reflection.
 boolean isFinal()
          Returns whether the field is final.
 boolean isPrimitive()
          Returns whether the field is primitive as defined by Data.isPrimitive(Type).
static boolean isPrimitive(Class<?> fieldClass)
          Deprecated. (scheduled to be removed in 1.5) Use Data.isPrimitive(Type)
static boolean isPrimitive(Object fieldValue)
          Deprecated. (scheduled to be removed in 1.5) Use Data.isPrimitive(Type) on the Object.getClass()
static FieldInfo of(Enum<?> enumValue)
          Returns the field information for the given enum value.
static FieldInfo of(Field field)
          Returns the field information for the given field.
static Object parsePrimitiveValue(Class<?> primitiveClass, String stringValue)
          Deprecated. (scheduled to be removed in 1.5) Use Data.parsePrimitiveValue(Type, String)
static void setFieldValue(Field field, Object obj, Object value)
          Sets to the given value of the given field in the given object instance using reflection.
 void setValue(Object obj, Object value)
          Sets to the given value of the field in the given object instance using reflection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isFinal

@Deprecated
public final boolean isFinal
Deprecated. (scheduled to be removed in 1.5) Use isFinal()
Whether the field is final.


isPrimitive

@Deprecated
public final boolean isPrimitive
Deprecated. (scheduled to be made private in 1.5) Use isPrimitive()
Whether the field class is "primitive" as defined by Data.isPrimitive(Type).


type

@Deprecated
public final Class<?> type
Deprecated. (scheduled to be removed in 1.5) Use getType()
Field class.


field

@Deprecated
public final Field field
Deprecated. (scheduled to be made private in 1.5) Use getField()
Field.


name

@Deprecated
public final String name
Deprecated. (scheduled to be made private in 1.5) Use getName()
Data key name associated with the field for a non-enum-constant with a Key annotation, or data key value associated with the enum constant with a Value annotation or null for an enum constant with a NullValue annotation.

This string is interned.

Method Detail

of

public static FieldInfo of(Enum<?> enumValue)
Returns the field information for the given enum value.

Parameters:
enumValue - enum value
Returns:
field information
Throws:
IllegalArgumentException - if the enum value has no value annotation
Since:
1.4

of

public static FieldInfo of(Field field)
Returns the field information for the given field.

Parameters:
field - field or null for null result
Returns:
field information or null if the field has no name or for null input

getField

public Field getField()
Returns the field.

Since:
1.4

getName

public String getName()
Returns the data key name associated with the field for a non-enum-constant with a Key annotation, or data key value associated with the enum constant with a Value annotation or null for an enum constant with a NullValue annotation.

This string is interned.

Since:
1.4

getType

public Class<?> getType()
Returns the field's type.

Since:
1.4

getGenericType

public Type getGenericType()
Returns the field's generic type, which is a class, parameterized type, generic array type, or type variable, but not a wildcard type.

Since:
1.4

isFinal

public boolean isFinal()
Returns whether the field is final.

Since:
1.4

isPrimitive

public boolean isPrimitive()
Returns whether the field is primitive as defined by Data.isPrimitive(Type).

Since:
1.4

getValue

public Object getValue(Object obj)
Returns the value of the field in the given object instance using reflection.


setValue

public void setValue(Object obj,
                     Object value)
Sets to the given value of the field in the given object instance using reflection.

If the field is final, it checks that value being set is identical to the existing value.


getClassInfo

public ClassInfo getClassInfo()
Returns the class information of the field's declaring class.


enumValue

public <T extends Enum<T>> T enumValue()

isPrimitive

@Deprecated
public static boolean isPrimitive(Class<?> fieldClass)
Deprecated. (scheduled to be removed in 1.5) Use Data.isPrimitive(Type)

Returns whether the given field class is one of the supported primitive types like number and date/time.


isPrimitive

@Deprecated
public static boolean isPrimitive(Object fieldValue)
Deprecated. (scheduled to be removed in 1.5) Use Data.isPrimitive(Type) on the Object.getClass()

Returns whether to given value is null or its class is primitive as defined by isPrimitive(Class).


getFieldValue

public static Object getFieldValue(Field field,
                                   Object obj)
Returns the value of the given field in the given object instance using reflection.


setFieldValue

public static void setFieldValue(Field field,
                                 Object obj,
                                 Object value)
Sets to the given value of the given field in the given object instance using reflection.

If the field is final, it checks that value being set is identical to the existing value.


parsePrimitiveValue

@Deprecated
public static Object parsePrimitiveValue(Class<?> primitiveClass,
                                                    String stringValue)
Deprecated. (scheduled to be removed in 1.5) Use Data.parsePrimitiveValue(Type, String)

Parses the given string value based on the given primitive class.

Types are parsed as follows:

Note that this may not be the right behavior for some use cases.

Parameters:
primitiveClass - primitive class (see isPrimitive(Class) or null to parse as a string
stringValue - string value to parse or null for null result
Returns:
parsed object or null for null input
Throws:
IllegalArgumentException - if the given class is not a primitive class as defined by isPrimitive(Class)


Copyright © 2010-2011 Google. All Rights Reserved.