nl.jqno.equalsverifier.util
Class ClassAccessor<T>

java.lang.Object
  extended by nl.jqno.equalsverifier.util.ClassAccessor<T>
Type Parameters:
T - A class.

public class ClassAccessor<T>
extends Object

Instantiates and populates objects of a given class. ClassAccessor can create two different instances of T, which are guaranteed not to be equal to each other, and which contain no null values.

Author:
Jan Ouwens

Method Summary
 boolean declaresEquals()
          Determines whether T has an equals method.
 boolean declaresField(Field field)
          Determines whether T declares a field.
 boolean declaresHashCode()
          Determines whether T has an hashCode method.
 boolean fieldHasAnnotation(Field field, Annotation annotation)
          Determines whether a particular field in T has a particular annotation.
 ObjectAccessor<T> getBlackAccessor()
          Returns an ObjectAccessor for getBlackObject().
 T getBlackObject()
          Returns an instance of T that is not equal to the instance of T returned by getRedObject().
 ObjectAccessor<T> getDefaultValuesAccessor()
          Returns an ObjectAccessor for getDefaultValuesObject().
 T getDefaultValuesObject()
          Returns an instance of T where all the fields are initialized to their default values.
 PrefabValues getPrefabValues()
          Getter.
 ObjectAccessor<T> getRedAccessor()
          Returns an ObjectAccessor for getRedObject().
 T getRedObject()
          Returns an instance of T that is not equal to the instance of T returned by getBlackObject().
 ClassAccessor<? super T> getSuperAccessor()
          Returns an accessor for T's superclass.
 Class<T> getType()
          Getter.
 boolean hasAnnotation(Annotation annotation)
          Determines whether T has a particular annotation.
 boolean isEqualsAbstract()
          Determines whether T's equals method is abstract.
 boolean isEqualsInheritedFromObject()
          Determines whether T's equals method is inherited from Object.
 boolean isHashCodeAbstract()
          Determines whether T's hashCode method is abstract.
static
<T> ClassAccessor<T>
of(Class<T> type, PrefabValues prefabValues, boolean ignoreAnnotationFailure)
          Factory method.
 boolean outerClassHasAnnotation(Annotation annotation)
          Determines whether any of T's outer classes, if they exist, have a particular annotation.
 boolean packageHasAnnotation(Annotation annotation)
          Determines whether the package in which T resides has a particular annotation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

of

public static <T> ClassAccessor<T> of(Class<T> type,
                                      PrefabValues prefabValues,
                                      boolean ignoreAnnotationFailure)
Factory method.

Type Parameters:
T - The class on which ClassAccessor operates.
Parameters:
type - The class on which ClassAccessor operates. Should be the same as T.
prefabValues - Prefabricated values with which to fill instantiated objects.
ignoreAnnotationFailure - Ignore when processing annotations fails.
Returns:
A ClassAccessor for T.

getType

public Class<T> getType()
Getter.


getPrefabValues

public PrefabValues getPrefabValues()
Getter.


hasAnnotation

public boolean hasAnnotation(Annotation annotation)
Determines whether T has a particular annotation.

Parameters:
annotation - The annotation we want to find.
Returns:
True if T has the specified annotation.

outerClassHasAnnotation

public boolean outerClassHasAnnotation(Annotation annotation)
Determines whether any of T's outer classes, if they exist, have a particular annotation.

Parameters:
annotation - The annotation we want to find.
Returns:
True if T has an outer class with the specified annotation.

packageHasAnnotation

public boolean packageHasAnnotation(Annotation annotation)
Determines whether the package in which T resides has a particular annotation.

Parameters:
annotation - The annotation we want to find.
Returns:
True if the package in which T resides has the specified annotation.

fieldHasAnnotation

public boolean fieldHasAnnotation(Field field,
                                  Annotation annotation)
Determines whether a particular field in T has a particular annotation.

Parameters:
field - The field for which we want to know if it has the specified annotation.
annotation - The annotation we want to find.
Returns:
True if the specified field in T has the specified annotation.

declaresField

public boolean declaresField(Field field)
Determines whether T declares a field. This does not include inherited fields.

Returns:
True if T declares the field.

declaresEquals

public boolean declaresEquals()
Determines whether T has an equals method.

Returns:
True if T has an equals method.

declaresHashCode

public boolean declaresHashCode()
Determines whether T has an hashCode method.

Returns:
True if T has an hashCode method.

isEqualsAbstract

public boolean isEqualsAbstract()
Determines whether T's equals method is abstract.

Returns:
True if T's equals method is abstract.

isHashCodeAbstract

public boolean isHashCodeAbstract()
Determines whether T's hashCode method is abstract.

Returns:
True if T's hashCode method is abstract.

isEqualsInheritedFromObject

public boolean isEqualsInheritedFromObject()
Determines whether T's equals method is inherited from Object.

Returns:
true if T's equals method is inherited from Object; false if it is overridden in T or in any of its superclasses (except Object).

getSuperAccessor

public ClassAccessor<? super T> getSuperAccessor()
Returns an accessor for T's superclass.

Returns:
An accessor for T's superclass.

getRedObject

public T getRedObject()
Returns an instance of T that is not equal to the instance of T returned by getBlackObject().

Returns:
An instance of T.

getRedAccessor

public ObjectAccessor<T> getRedAccessor()
Returns an ObjectAccessor for getRedObject().

Returns:
An ObjectAccessor for getRedObject().

getBlackObject

public T getBlackObject()
Returns an instance of T that is not equal to the instance of T returned by getRedObject().

Returns:
An instance of T.

getBlackAccessor

public ObjectAccessor<T> getBlackAccessor()
Returns an ObjectAccessor for getBlackObject().

Returns:
An ObjectAccessor for getBlackObject().

getDefaultValuesObject

public T getDefaultValuesObject()
Returns an instance of T where all the fields are initialized to their default values. I.e., 0 for ints, and null for objects (except when the field is marked with a NonNull annotation).

Returns:
An instance of T where all the fields are initialized to their default values.

getDefaultValuesAccessor

public ObjectAccessor<T> getDefaultValuesAccessor()
Returns an ObjectAccessor for getDefaultValuesObject().

Returns:
An ObjectAccessor for getDefaultValuesObject().


Copyright © 2015. All Rights Reserved.