Record Class RecordField

java.lang.Object
java.lang.Record
st.orm.mapping.RecordField
Record Components:
declaringType - the class that declares this record field.
name - the name of the record field.
type - the raw type of the field.
genericType - the generic type of the field, preserving type parameters.
nullable - whether the field value can be null.
mutable - whether the field value can be modified.
method - the accessor method for this field.
annotations - all annotations present on this field.

public record RecordField(@Nonnull Class<?> declaringType, @Nonnull String name, @Nonnull Class<?> type, @Nonnull Type genericType, boolean nullable, boolean mutable, @Nonnull Method method, @Nonnull List<Annotation> annotations) extends Record
Represents metadata about a field in a data record type.

This record captures all relevant information about a record fields, including its type information, annotations, and the accessor method used to retrieve its value. It provides convenient methods for working with annotations and for invoking the accessor method.

Since:
1.7
  • Constructor Details

    • RecordField

      public RecordField(@Nonnull Class<?> declaringType, @Nonnull String name, @Nonnull Class<?> type, @Nonnull Type genericType, boolean nullable, boolean mutable, @Nonnull Method method, @Nonnull List<Annotation> annotations)
      Creates an instance of a RecordField record class.
      Parameters:
      declaringType - the value for the declaringType record component
      name - the value for the name record component
      type - the value for the type record component
      genericType - the value for the genericType record component
      nullable - the value for the nullable record component
      mutable - the value for the mutable record component
      method - the value for the method record component
      annotations - the value for the annotations record component
  • Method Details

    • isDataType

      public boolean isDataType()
      Checks whether this field's type is a Data type.
      Returns:
      true if the field type implements or extends Data
    • requireDataType

      public Class<? extends Data> requireDataType()
      Returns the field type as a Data subtype, or throws an exception if the type does not implement Data.
      Returns:
      the field type cast to Class<? extends Data>
      Throws:
      PersistenceException - if the field type does not implement Data
    • isAnnotationPresent

      public boolean isAnnotationPresent(@Nonnull Class<? extends Annotation> annotationType)
      Checks whether an annotation of the specified type is present on this field.

      This method properly handles repeatable annotations, finding them whether they appear directly or wrapped in their container annotation.

      Parameters:
      annotationType - the annotation type to look for
      Returns:
      true if at least one annotation of the specified type is present
    • getAnnotations

      public <A extends Annotation> A[] getAnnotations(@Nonnull Class<A> annotationType)
      Returns all annotations of the specified type present on this field.

      This method properly handles repeatable annotations by unwrapping them from their container annotation when multiple instances are present.

      Type Parameters:
      A - the type of the annotation
      Parameters:
      annotationType - the annotation type to retrieve
      Returns:
      an array of all matching annotations, or an empty array if none are found
    • getAnnotation

      public <A extends Annotation> A getAnnotation(@Nonnull Class<A> annotationType)
      Returns a single annotation of the specified type from this field, or null if not present or if multiple instances are found.

      If multiple instances of a repeatable annotation are present, this method returns null to indicate ambiguity. Use getAnnotations(Class) to retrieve all instances.

      Type Parameters:
      A - the type of the annotation
      Parameters:
      annotationType - the annotation type to retrieve
      Returns:
      the annotation if exactly one instance is present, otherwise null
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • declaringType

      @Nonnull public Class<?> declaringType()
      Returns the value of the declaringType record component.
      Returns:
      the value of the declaringType record component
    • name

      @Nonnull public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • type

      @Nonnull public Class<?> type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • genericType

      @Nonnull public Type genericType()
      Returns the value of the genericType record component.
      Returns:
      the value of the genericType record component
    • nullable

      public boolean nullable()
      Returns the value of the nullable record component.
      Returns:
      the value of the nullable record component
    • mutable

      public boolean mutable()
      Returns the value of the mutable record component.
      Returns:
      the value of the mutable record component
    • method

      @Nonnull public Method method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component
    • annotations

      @Nonnull public List<Annotation> annotations()
      Returns the value of the annotations record component.
      Returns:
      the value of the annotations record component