Class ClassAccessor<T>
java.lang.Object
nl.jqno.equalsverifier.internal.reflection.ClassAccessor<T>
- Type Parameters:
T
- A class.
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
Modifier and TypeMethodDescriptionboolean
Determines whether T has anequals
method.boolean
declaresField
(Field field) Determines whether T declares a field.boolean
Determines whether T has anhashCode
method.getBlueAccessor
(TypeTag enclosingType) Returns anObjectAccessor
forgetBlueObject(TypeTag)
.getBlueObject
(TypeTag enclosingType) Returns an instance of T that is not equal to the instance of T returned bygetRedObject(TypeTag)
.getDefaultValuesAccessor
(TypeTag enclosingType, boolean isWarningNullSuppressed, boolean isWarningZeroSuppressed, Set<String> nonnullFields, AnnotationCache annotationCache) Returns anObjectAccessor
for an instance of T where all the fields are initialized to their default values.getRedAccessor
(TypeTag enclosingType) Returns anObjectAccessor
forgetRedObject(TypeTag)
.getRedObject
(TypeTag enclosingType) Returns an instance of T that is not equal to the instance of T returned bygetBlueObject(TypeTag)
.ClassAccessor<? super T>
Returns an accessor for T's superclass.getType()
boolean
boolean
Determines whether T'sequals
method is abstract.boolean
Determines whether T'sequals
method is inherited fromObject
.boolean
Determines whether T'shashCode
method is abstract.boolean
isRecord()
Determines whether T is a Java Record.boolean
isSealed()
Determines whether T is a sealed class.static <T> ClassAccessor<T>
of
(Class<T> type, PrefabValues prefabValues) Factory method.
-
Method Details
-
of
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
- Returns:
- The class on which
ClassAccessor
operates.
-
isRecord
public boolean isRecord()Determines whether T is a Java Record.- Returns:
- true if T is a Java Record.
-
isSealed
public boolean isSealed()Determines whether T is a sealed class.- Returns:
- true if T is a sealed class
-
declaresField
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.
-
hasMethod
-
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
. -
getSuperAccessor
Returns an accessor for T's superclass.- Returns:
- An accessor for T's superclass.
-
getRedObject
Returns an instance of T that is not equal to the instance of T returned bygetBlueObject(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
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)
.
-
getBlueObject
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.
-
getBlueAccessor
Returns anObjectAccessor
forgetBlueObject(TypeTag)
.- Parameters:
enclosingType
- Describes the type that contains this object as a field, to determine any generic parameters it may contain.- Returns:
- An
ObjectAccessor
forgetBlueObject(TypeTag)
.
-
getDefaultValuesAccessor
public ObjectAccessor<T> getDefaultValuesAccessor(TypeTag enclosingType, boolean isWarningNullSuppressed, boolean isWarningZeroSuppressed, Set<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.isWarningNullSuppressed
- Whether reference fields must be non-null (a.k.a., whether Warnings.NULL_FIELDS is suppressed).isWarningZeroSuppressed
- Whether primitive fields must be non-0 (a.k.a., whether Warnings.ZERO_FIELDS is suppressed).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.
-