Class ClassAccessor<T>
- java.lang.Object
-
- nl.jqno.equalsverifier.internal.reflection.ClassAccessor<T>
-
- Type Parameters:
T
- A class.
public class ClassAccessor<T> extends java.lang.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
declaresEquals()
Determines whether T has anequals
method.boolean
declaresField(java.lang.reflect.Field field)
Determines whether T declares a field.boolean
declaresHashCode()
Determines whether T has anhashCode
method.ObjectAccessor<T>
getBlackAccessor(TypeTag enclosingType)
Returns anObjectAccessor
forgetBlackObject(TypeTag)
.T
getBlackObject(TypeTag enclosingType)
Returns an instance of T that is not equal to the instance of T returned bygetRedObject(TypeTag)
.ObjectAccessor<T>
getDefaultValuesAccessor(TypeTag enclosingType, java.util.Set<java.lang.String> nonnullFields, AnnotationCache annotationCache)
Returns anObjectAccessor
for an instance of T where all the fields are initialized to their default values.ObjectAccessor<T>
getRedAccessor(TypeTag enclosingType)
Returns anObjectAccessor
forgetRedObject(TypeTag)
.T
getRedObject(TypeTag enclosingType)
Returns an instance of T that is not equal to the instance of T returned bygetBlackObject(TypeTag)
.ClassAccessor<? super T>
getSuperAccessor()
Returns an accessor for T's superclass.java.lang.Class<T>
getType()
boolean
isEqualsAbstract()
Determines whether T'sequals
method is abstract.boolean
isEqualsInheritedFromObject()
Determines whether T'sequals
method is inherited fromObject
.boolean
isHashCodeAbstract()
Determines whether T'shashCode
method is abstract.static <T> ClassAccessor<T>
of(java.lang.Class<T> type, PrefabValues prefabValues)
Factory method.
-
-
-
Method Detail
-
of
public static <T> ClassAccessor<T> of(java.lang.Class<T> type, PrefabValues prefabValues)
Factory method.- Type Parameters:
T
- The class on whichClassAccessor
operates.- Parameters:
type
- The class on whichClassAccessor
operates. Should be the same as T.prefabValues
- Prefabricated values with which to fill instantiated objects.- Returns:
- A
ClassAccessor
for T.
-
getType
public java.lang.Class<T> getType()
- Returns:
- The class on which
ClassAccessor
operates.
-
declaresField
public boolean declaresField(java.lang.reflect.Field field)
Determines whether T declares a field. This does not include inherited fields.- Parameters:
field
- The field that we want to detect.- Returns:
- True if T declares the field.
-
declaresEquals
public boolean declaresEquals()
Determines whether T has anequals
method.- Returns:
- True if T has an
equals
method.
-
declaresHashCode
public boolean declaresHashCode()
Determines whether T has anhashCode
method.- Returns:
- True if T has an
hashCode
method.
-
isEqualsAbstract
public boolean isEqualsAbstract()
Determines whether T'sequals
method is abstract.- Returns:
- True if T's
equals
method is abstract.
-
isHashCodeAbstract
public boolean isHashCodeAbstract()
Determines whether T'shashCode
method is abstract.- Returns:
- True if T's
hashCode
method is abstract.
-
isEqualsInheritedFromObject
public boolean isEqualsInheritedFromObject()
Determines whether T'sequals
method is inherited fromObject
.- Returns:
- true if T's
equals
method is inherited fromObject
; false if it is overridden in T or in any of its superclasses (exceptObject
).
-
getSuperAccessor
public ClassAccessor<? super T> getSuperAccessor()
Returns an accessor for T's superclass.- Returns:
- An accessor for T's superclass.
-
getRedObject
public T getRedObject(TypeTag enclosingType)
Returns an instance of T that is not equal to the instance of T returned bygetBlackObject(TypeTag)
.- Parameters:
enclosingType
- Describes the type that contains this object as a field, to determine any generic parameters it may contain.- Returns:
- An instance of T.
-
getRedAccessor
public ObjectAccessor<T> getRedAccessor(TypeTag enclosingType)
Returns anObjectAccessor
forgetRedObject(TypeTag)
.- Parameters:
enclosingType
- Describes the type that contains this object as a field, to determine any generic parameters it may contain.- Returns:
- An
ObjectAccessor
forgetRedObject(TypeTag)
.
-
getBlackObject
public T getBlackObject(TypeTag enclosingType)
Returns an instance of T that is not equal to the instance of T returned bygetRedObject(TypeTag)
.- Parameters:
enclosingType
- Describes the type that contains this object as a field, to determine any generic parameters it may contain.- Returns:
- An instance of T.
-
getBlackAccessor
public ObjectAccessor<T> getBlackAccessor(TypeTag enclosingType)
Returns anObjectAccessor
forgetBlackObject(TypeTag)
.- Parameters:
enclosingType
- Describes the type that contains this object as a field, to determine any generic parameters it may contain.- Returns:
- An
ObjectAccessor
forgetBlackObject(TypeTag)
.
-
getDefaultValuesAccessor
public ObjectAccessor<T> getDefaultValuesAccessor(TypeTag enclosingType, java.util.Set<java.lang.String> nonnullFields, AnnotationCache annotationCache)
Returns anObjectAccessor
for 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).- Parameters:
enclosingType
- Describes the type that contains this object as a field, to determine any generic parameters it may contain.nonnullFields
- Fields which are not allowed to be set to null.annotationCache
- To check for any NonNull annotations.- Returns:
- An
ObjectAccessor
for an instance of T where all the fields are initialized to their default values.
-
-