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 TypeMethodDescriptionbooleanDetermines whether T has anequalsmethod.booleandeclaresField(Field field) Determines whether T declares a field.booleanDetermines whether T has anhashCodemethod.getBlueAccessor(TypeTag enclosingType) Returns anObjectAccessorforgetBlueObject(TypeTag).getBlueAccessor(TypeTag enclosingType, LinkedHashSet<TypeTag> typeStack) Returns anObjectAccessorforgetBlueObject(TypeTag).getBlueObject(TypeTag enclosingType) Returns an instance of T that is not equal to the instance of T returned bygetRedObject(TypeTag).getBlueObject(TypeTag enclosingType, LinkedHashSet<TypeTag> typeStack) 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 anObjectAccessorfor an instance of T where all the fields are initialized to their default values.getRedAccessor(TypeTag enclosingType) Returns anObjectAccessorforgetRedObject(TypeTag).getRedAccessor(TypeTag enclosingType, LinkedHashSet<TypeTag> typeStack) Returns anObjectAccessorforgetRedObject(TypeTag).getRedObject(TypeTag enclosingType) Returns an instance of T that is not equal to the instance of T returned bygetBlueObject(TypeTag).getRedObject(TypeTag enclosingType, LinkedHashSet<TypeTag> typeStack) 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()booleanDetermines whether T has a method with the given name and parameters.booleanDetermines whether T'sequalsmethod is abstract.booleanDetermines whether T'sequalsmethod is inherited fromObject.booleanDetermines whether T'shashCodemethod is abstract.booleanisRecord()Determines whether T is a Java Record.booleanisSealed()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 whichClassAccessoroperates.- Parameters:
type- The class on whichClassAccessoroperates. Should be the same as T.prefabValues- Prefabricated values with which to fill instantiated objects.- Returns:
- A
ClassAccessorfor T.
-
getType
- Returns:
- The class on which
ClassAccessoroperates.
-
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 anequalsmethod.- Returns:
- True if T has an
equalsmethod.
-
declaresHashCode
public boolean declaresHashCode()Determines whether T has anhashCodemethod.- Returns:
- True if T has an
hashCodemethod.
-
hasMethod
Determines whether T has a method with the given name and parameters.- Parameters:
name- The name of the method we're looking for.- Returns:
- True if T has a method with the given name and parameters.
-
isEqualsAbstract
public boolean isEqualsAbstract()Determines whether T'sequalsmethod is abstract.- Returns:
- True if T's
equalsmethod is abstract.
-
isHashCodeAbstract
public boolean isHashCodeAbstract()Determines whether T'shashCodemethod is abstract.- Returns:
- True if T's
hashCodemethod is abstract.
-
isEqualsInheritedFromObject
public boolean isEqualsInheritedFromObject()Determines whether T'sequalsmethod 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.
-
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.typeStack- Keeps track of recursion in the type.- Returns:
- An instance of T.
-
getRedAccessor
Returns anObjectAccessorforgetRedObject(TypeTag).- Parameters:
enclosingType- Describes the type that contains this object as a field, to determine any generic parameters it may contain.- Returns:
- An
ObjectAccessorforgetRedObject(TypeTag).
-
getRedAccessor
Returns anObjectAccessorforgetRedObject(TypeTag).- Parameters:
enclosingType- Describes the type that contains this object as a field, to determine any generic parameters it may contain.typeStack- Keeps track of recursion in the type.- Returns:
- An
ObjectAccessorforgetRedObject(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.
-
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.typeStack- Keeps track of recursion in the type.- Returns:
- An instance of T.
-
getBlueAccessor
Returns anObjectAccessorforgetBlueObject(TypeTag).- Parameters:
enclosingType- Describes the type that contains this object as a field, to determine any generic parameters it may contain.- Returns:
- An
ObjectAccessorforgetBlueObject(TypeTag).
-
getBlueAccessor
Returns anObjectAccessorforgetBlueObject(TypeTag).- Parameters:
enclosingType- Describes the type that contains this object as a field, to determine any generic parameters it may contain.typeStack- Keeps track of recursion in the type.- Returns:
- An
ObjectAccessorforgetBlueObject(TypeTag).
-
getDefaultValuesAccessor
public ObjectAccessor<T> getDefaultValuesAccessor(TypeTag enclosingType, boolean isWarningNullSuppressed, boolean isWarningZeroSuppressed, Set<String> nonnullFields, AnnotationCache annotationCache) Returns anObjectAccessorfor 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
ObjectAccessorfor an instance of T where all the fields are initialized to their default values.
-