net.craftforge.reflection.utils
Class ReflUtils

java.lang.Object
  extended by net.craftforge.reflection.utils.ReflUtils

public class ReflUtils
extends Object

Since:
02.12.2010
Author:
Christian Bick

Constructor Summary
ReflUtils()
           
 
Method Summary
static
<T> Collection<T>
createCollection(Class<?> collectionType)
          Creates a parametrized collection of the given collection type (e.g.
static String getterName(String fieldName)
          Builds the name of the get-method for the given field name.
static boolean isActualReference(Class<?> c)
          Checks if the class represents an actual reference.
static boolean isCollection(Class<?> c)
          Checks if the class is a collection (implements interface collection).
static boolean isCollectionData(Field field)
          Checks if the reference is a collection of data fields.
static boolean isCollectionReference(Field field)
          Checks if the collection is a collection of references
static boolean isPrimitive(Class<?> c)
          Checks if the class a primitive, including primitive objects (Integer, Long etc.).
static boolean isSingleActualReference(Field field)
          Checks if the field is a reference field.
static boolean isSingleVirtualPrimitive(Field field)
          Checks if the field is a data field.
static boolean isVirtualPrimitive(Class<?> c)
          Checks if the class represents a virtual primitive.
static Class<?> primitiveToObject(Class<?> primitiveClass)
          Converts a primitive class to its equivalent object class.
static String setterName(String fieldName)
          Builds the name of the set-method for the given field name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflUtils

public ReflUtils()
Method Detail

primitiveToObject

public static Class<?> primitiveToObject(Class<?> primitiveClass)

Converts a primitive class to its equivalent object class. Will return the original class if it is no primitive.

Examples: int -> Integer, char -> Character, Float -> Float

Parameters:
primitiveClass - The primitive class
Returns:
The equivalent object class

isPrimitive

public static boolean isPrimitive(Class<?> c)
Checks if the class a primitive, including primitive objects (Integer, Long etc.).

Parameters:
c - The class
Returns:
true, if the class is a primitive, false otherwise

isVirtualPrimitive

public static boolean isVirtualPrimitive(Class<?> c)
Checks if the class represents a virtual primitive. Virtual primitives are a all real primitives, their object representation (Integer, Long etc.) as well as String and Date.

Parameters:
c - The class
Returns:
true, if the class is a simple data type, false otherwise

isActualReference

public static boolean isActualReference(Class<?> c)
Checks if the class represents an actual reference. Actual references are represented by all classes that are not virtual primitives. So this method ignores references to primitive objects (Integer, Long, etc.) as well as to String and Date.

Parameters:
c - The class
Returns:
true, if the class is not a simple data type, false otherwise

isCollection

public static boolean isCollection(Class<?> c)
Checks if the class is a collection (implements interface collection).

Parameters:
c - The class
Returns:
true, if the field type is a collection, false otherwise

isSingleVirtualPrimitive

public static boolean isSingleVirtualPrimitive(Field field)
Checks if the field is a data field.

Parameters:
field - The field
Returns:
true, if the field is a data field but no collection, false otherwise

isSingleActualReference

public static boolean isSingleActualReference(Field field)
Checks if the field is a reference field.

Parameters:
field - The field
Returns:
true, if the field is a reference field but no collection, false otherwise

isCollectionData

public static boolean isCollectionData(Field field)
Checks if the reference is a collection of data fields.

Parameters:
field - The field
Returns:
true, if the field is a collection of data fields, false otherwise

isCollectionReference

public static boolean isCollectionReference(Field field)
Checks if the collection is a collection of references

Parameters:
field - The field
Returns:
true, if the field is a collection of reference fields, false otherwise

getterName

public static String getterName(String fieldName)
Builds the name of the get-method for the given field name.

Parameters:
fieldName - The field name
Returns:
The get-method's name

setterName

public static String setterName(String fieldName)
Builds the name of the set-method for the given field name.

Parameters:
fieldName - The field name
Returns:
The set-method's name

createCollection

public static <T> Collection<T> createCollection(Class<?> collectionType)
Creates a parametrized collection of the given collection type (e.g. List) using the given generic type as generic parameter.

Example: createCollection(List.class, String.class) will return a collection of type List<String>

Type Parameters:
T - The class parameter
Parameters:
collectionType - The collection type
Returns:
The created collection


Copyright © 2011. All Rights Reserved.