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

      • 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.
      • isRecord

        public boolean isRecord()
        Determines whether T is a Java Record.
        Returns:
        True if T is a Java Record.
      • 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.
      • 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.
      • 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.
      • getDefaultValuesAccessor

        public ObjectAccessor<T> getDefaultValuesAccessor​(TypeTag enclosingType,
                                                          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.
        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.