com.healthmarketscience.common.util
Class ClassUtil

java.lang.Object
  extended by com.healthmarketscience.common.util.ClassUtil

public class ClassUtil
extends Object

Static utility methods for working with classes and reflection.


Constructor Summary
ClassUtil()
           
 
Method Summary
static boolean fieldIsBoolean(Field field)
          Test if the field is a Boolean or boolean.
static
<AType extends Annotation,MType extends AnnotatedElement>
Collection<Tuple2<AType,MType>>
findAnnotatedElements(Class<AType> annotationClass, MType... members)
          Search for elements (fields or methods) which have the given annotation.
static
<AType extends Annotation>
Collection<Tuple2<AType,Field>>
findAnnotatedFields(Object instance, Class<AType> annotationClass, boolean inherit)
          Get a collection of fields of the given object with the given annotation.
static
<AType extends Annotation>
Collection<Tuple2<AType,Method>>
findAnnotatedMethods(Object instance, Class<AType> annotationClass, boolean inherit)
          Get a collection of methods of the given object with the given annotation.
static boolean isBoolean(Class<?> clazz)
          Test if the class is Boolean or boolean.
static boolean methodTakesBoolean(Method method)
          Test if the method takes one and only one arg which is a Boolean or boolean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtil

public ClassUtil()
Method Detail

findAnnotatedFields

public static <AType extends Annotation> Collection<Tuple2<AType,Field>> findAnnotatedFields(Object instance,
                                                                                             Class<AType> annotationClass,
                                                                                             boolean inherit)
Get a collection of fields of the given object with the given annotation.

Type Parameters:
AType - the type of the annotation to look for.
Parameters:
instance - the object to scan for annotated fields.
annotationClass - the type of the annotation to look for.
inherit - whether to get fields from super classes.
Returns:
a collection of pairs of fields and their annotations

findAnnotatedMethods

public static <AType extends Annotation> Collection<Tuple2<AType,Method>> findAnnotatedMethods(Object instance,
                                                                                               Class<AType> annotationClass,
                                                                                               boolean inherit)
Get a collection of methods of the given object with the given annotation.

Type Parameters:
AType - the type of the annotation to look for.
Parameters:
instance - the object to scan for annotated methods.
annotationClass - the type of the annotation to look for.
inherit - whether to get methods from super classes.
Returns:
a collection of pairs of methods and their annotations

findAnnotatedElements

public static <AType extends Annotation,MType extends AnnotatedElement> Collection<Tuple2<AType,MType>> findAnnotatedElements(Class<AType> annotationClass,
                                                                                                                              MType... members)
Search for elements (fields or methods) which have the given annotation.

Parameters:
annotationClass - the annotation to search for
members - the members to search over
Returns:
a collection of the members with the annotation (an empty collection if none are found)

isBoolean

public static boolean isBoolean(Class<?> clazz)
Test if the class is Boolean or boolean.


methodTakesBoolean

public static boolean methodTakesBoolean(Method method)
Test if the method takes one and only one arg which is a Boolean or boolean.


fieldIsBoolean

public static boolean fieldIsBoolean(Field field)
Test if the field is a Boolean or boolean.



Copyright © 2006-2016 Health Market Science. All Rights Reserved.