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 Summary
ConstructorsConstructorDescriptionRecordField(Class<?> declaringType, String name, Class<?> type, Type genericType, boolean nullable, boolean mutable, Method method, List<Annotation> annotations) Creates an instance of aRecordFieldrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theannotationsrecord component.Class<?> Returns the value of thedeclaringTyperecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of thegenericTyperecord component.<A extends Annotation>
AgetAnnotation(Class<A> annotationType) Returns a single annotation of the specified type from this field, ornullif not present or if multiple instances are found.<A extends Annotation>
A[]getAnnotations(Class<A> annotationType) Returns all annotations of the specified type present on this field.final inthashCode()Returns a hash code value for this object.booleanisAnnotationPresent(Class<? extends Annotation> annotationType) Checks whether an annotation of the specified type is present on this field.booleanChecks whether this field's type is aDatatype.method()Returns the value of themethodrecord component.booleanmutable()Returns the value of themutablerecord component.name()Returns the value of thenamerecord component.booleannullable()Returns the value of thenullablerecord component.final StringtoString()Returns a string representation of this record class.Class<?> type()Returns the value of thetyperecord component.
-
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 aRecordFieldrecord class.- Parameters:
declaringType- the value for thedeclaringTyperecord componentname- the value for thenamerecord componenttype- the value for thetyperecord componentgenericType- the value for thegenericTyperecord componentnullable- the value for thenullablerecord componentmutable- the value for themutablerecord componentmethod- the value for themethodrecord componentannotations- the value for theannotationsrecord component
-
-
Method Details
-
isDataType
public boolean isDataType()Checks whether this field's type is aDatatype.- Returns:
trueif the field type implements or extendsData
-
requireDataType
Returns the field type as aDatasubtype, or throws an exception if the type does not implementData.- Returns:
- the field type cast to
Class<? extends Data> - Throws:
PersistenceException- if the field type does not implementData
-
isAnnotationPresent
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:
trueif at least one annotation of the specified type is present
-
getAnnotations
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
Returns a single annotation of the specified type from this field, ornullif not present or if multiple instances are found.If multiple instances of a repeatable annotation are present, this method returns
nullto indicate ambiguity. UsegetAnnotations(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
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
declaringType
Returns the value of thedeclaringTyperecord component.- Returns:
- the value of the
declaringTyperecord component
-
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
type
Returns the value of thetyperecord component.- Returns:
- the value of the
typerecord component
-
genericType
Returns the value of thegenericTyperecord component.- Returns:
- the value of the
genericTyperecord component
-
nullable
public boolean nullable()Returns the value of thenullablerecord component.- Returns:
- the value of the
nullablerecord component
-
mutable
public boolean mutable()Returns the value of themutablerecord component.- Returns:
- the value of the
mutablerecord component
-
method
Returns the value of themethodrecord component.- Returns:
- the value of the
methodrecord component
-
annotations
Returns the value of theannotationsrecord component.- Returns:
- the value of the
annotationsrecord component
-