Build 1.0_r1(from source)

java.lang
Class ClassCache<T>

java.lang.Object
  extended by java.lang.ClassCache<T>

 class ClassCache<T>
extends Object

Cache of per-class data, meant to help the performance of reflection methods.

Note: None of the methods perform access checks. It is up to the (package internal) clients of this code to perform such checks as necessary.

Also Note: None of the returned array values are protected in any way. It is up to the (again, package internal) clients of this code to protect the arrays if they should ever escape the package.


Field Summary
(package private) static org.apache.harmony.kernel.vm.ReflectionAccess REFLECT
          non-null; reflection access bridge
 
Constructor Summary
ClassCache(Class<T> clazz)
          Constructs an instance.
 
Method Summary
static boolean compareClassLists(Class<?>[] a, Class<?>[] b)
          Compares two class lists for equality.
static Method[] deepCopy(Method[] orig)
          Makes a deep copy of the given array of methods.
 Method[] getAllMethods()
          Gets the list of all methods, both directly declared and inherited.
 Method[] getAllPublicMethods()
          Gets the list of all public methods, both directly declared and inherited.
 Method[] getDeclaredMethods()
          Gets the list of all declared methods.
 Method[] getDeclaredMethods(boolean publicOnly)
          Gets either the list of declared methods or the list of declared public methods.
 Method[] getDeclaredPublicMethods()
          Gets the list of all declared public methods.
 T getEnumValue(String name)
          Gets the enumerated value with a given name.
 T[] getEnumValuesByName()
          Gets the array of enumerated values, sorted by name.
 T[] getEnumValuesInOrder()
          Gets the array of enumerated values, in their original declared order.
static Method getMatchingMethod(Method[] list, String name, Class<?>[] parameterTypes)
          Finds and returns a method with a given name and signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REFLECT

static final org.apache.harmony.kernel.vm.ReflectionAccess REFLECT
non-null; reflection access bridge

Constructor Detail

ClassCache

ClassCache(Class<T> clazz)
Constructs an instance.

Parameters:
clazz - non-null; class that this instance represents
Method Detail

getDeclaredMethods

public Method[] getDeclaredMethods()
Gets the list of all declared methods.

Returns:
non-null; the list of all declared methods

getDeclaredPublicMethods

public Method[] getDeclaredPublicMethods()
Gets the list of all declared public methods.

Returns:
non-null; the list of all declared public methods

getDeclaredMethods

public Method[] getDeclaredMethods(boolean publicOnly)
Gets either the list of declared methods or the list of declared public methods.

Parameters:
publicOnly - whether to only return public methods

getAllMethods

public Method[] getAllMethods()
Gets the list of all methods, both directly declared and inherited.

Returns:
non-null; the list of all methods

getAllPublicMethods

public Method[] getAllPublicMethods()
Gets the list of all public methods, both directly declared and inherited.

Returns:
non-null; the list of all public methods

getMatchingMethod

public static Method getMatchingMethod(Method[] list,
                                       String name,
                                       Class<?>[] parameterTypes)
                                throws NoSuchMethodException
Finds and returns a method with a given name and signature. Use this with one of the method lists returned by instances of this class.

Parameters:
list - non-null; the list of methods to search through
parameterTypes - non-null; the formal parameter list
Returns:
non-null; the matching method
Throws:
NoSuchMethodExcpetion - thrown if the method does not exist
NoSuchMethodException

compareClassLists

public static boolean compareClassLists(Class<?>[] a,
                                        Class<?>[] b)
Compares two class lists for equality. Empty and null lists are considered equal. This is useful for matching methods and constructors.

TODO: Take into account assignment compatibility?

Parameters:
a - null-ok; the first list of types
b - null-ok; the second list of types
Returns:
true if and only if the lists are equal

deepCopy

public static Method[] deepCopy(Method[] orig)
Makes a deep copy of the given array of methods. This is useful when handing out arrays from the public API.

Note: In such cases, it is insufficient to just make a shallow copy of the array, since method objects aren't immutable due to the existence of AccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean).

Parameters:
orig - non-null; array to copy
Returns:
non-null; a deep copy of the given array

getEnumValue

public T getEnumValue(String name)
Gets the enumerated value with a given name.

Parameters:
name - non-null; name of the value
Returns:
null-ok; the named enumerated value or null if this instance's class doesn't have such a value (including if this instance isn't in fact an enumeration)

getEnumValuesByName

public T[] getEnumValuesByName()
Gets the array of enumerated values, sorted by name.

Returns:
null-ok; the value array, or null if this instance's class isn't in fact an enumeration

getEnumValuesInOrder

public T[] getEnumValuesInOrder()
Gets the array of enumerated values, in their original declared order.

Returns:
null-ok; the value array, or null if this instance's class isn't in fact an enumeration

Build 1.0_r1(from source)

Please submit a feedback, bug or feature