Class ClassAccessor<T>

java.lang.Object
nl.jqno.equalsverifier.internal.reflection.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.
  • Method Details

    • of

      public static <T> ClassAccessor<T> of(Class<T> type, PrefabValues prefabValues)
      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.
      Returns:
      A ClassAccessor for T.
    • getType

      public Class<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

      public boolean declaresField(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 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.
    • hasMethod

      public boolean hasMethod(String name, Class<?>... parameterTypes)
    • 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(TypeTag enclosingType)
      Returns an instance of T that is not equal to the instance of T returned by getBlueObject(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)
      Parameters:
      enclosingType - Describes the type that contains this object as a field, to determine any generic parameters it may contain.
      Returns:
      An ObjectAccessor for getRedObject(TypeTag).
    • getBlueObject

      public T getBlueObject(TypeTag enclosingType)
      Returns an instance of T that is not equal to the instance of T returned by getRedObject(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

      public ObjectAccessor<T> getBlueAccessor(TypeTag enclosingType)
      Parameters:
      enclosingType - Describes the type that contains this object as a field, to determine any generic parameters it may contain.
      Returns:
      An ObjectAccessor for getBlueObject(TypeTag).
    • getDefaultValuesAccessor

      public ObjectAccessor<T> getDefaultValuesAccessor(TypeTag enclosingType, boolean isWarningNullSuppressed, boolean isWarningZeroSuppressed, Set<String> nonnullFields, AnnotationCache annotationCache)
      Returns an ObjectAccessor 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.