Class DirectFieldAccessor

java.lang.Object
org.litebridgedb.tracking.DirectFieldAccessor
All Implemented Interfaces:
FieldAccessor

public final class DirectFieldAccessor extends Object implements FieldAccessor
Direct field access FieldAccessor implementation using Java 9's VarHandle.

Provides functionality for accessing and manipulating fields of a data transfer object (DTO) directly using Java Reflection.

This class enables retrieving field names, types, generic types, and the declaring class. It also supports getting and setting field values within a given DTO instance.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the parent Class of the DTO containing the field targeted by this FieldAccessor.
    boolean
     
    Class<?>[]
    Returns an array of Class objects representing the generic types associated with the field or property represented by this FieldAccessor.
    get(Object dto)
    Retrieve the value of a field or property from the provided data transfer object (DTO).
    int
     
    Return the name of the field or property represented by this FieldAccessor.
    void
    set(Object dto, @Nullable Object value)
    Set the value of a field or property for the provided data transfer object (DTO).
     
    Returns the declared type for the field represented by this FieldAccessor.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.litebridgedb.tracking.FieldAccessor

    genericType
  • Constructor Details

  • Method Details

    • name

      public String name()
      Description copied from interface: FieldAccessor
      Return the name of the field or property represented by this FieldAccessor.
      Specified by:
      name in interface FieldAccessor
      Returns:
      the name of the field or property as a String
    • get

      public Object get(Object dto)
      Description copied from interface: FieldAccessor
      Retrieve the value of a field or property from the provided data transfer object (DTO).
      Specified by:
      get in interface FieldAccessor
      Parameters:
      dto - the data transfer object from which to retrieve the field or property value. Must not be null and should conform to the structure expected by this FieldAccessor.
      Returns:
      the value of the field or property, or null if the field value is null or could not be accessed.
    • set

      public void set(Object dto, @Nullable Object value)
      Description copied from interface: FieldAccessor
      Set the value of a field or property for the provided data transfer object (DTO).
      Specified by:
      set in interface FieldAccessor
      Parameters:
      dto - the data transfer object for which the field or property value will be set. Must not be null and should conform to the structure expected by this FieldAccessor.
      value - the value to set for the field or property. May be null if the field or property allows null values.
    • type

      public Class<?> type()
      Description copied from interface: FieldAccessor
      Returns the declared type for the field represented by this FieldAccessor.
      Specified by:
      type in interface FieldAccessor
      Returns:
      the field type
    • genericTypes

      public Class<?>[] genericTypes()
      Description copied from interface: FieldAccessor
      Returns an array of Class objects representing the generic types associated with the field or property represented by this FieldAccessor.
      Specified by:
      genericTypes in interface FieldAccessor
      Returns:
      an array of Class objects that represent the generic types of the field or property, or an empty array if the field or property does not use generics.
    • dtoClass

      public Class<?> dtoClass()
      Description copied from interface: FieldAccessor
      Retrieves the parent Class of the DTO containing the field targeted by this FieldAccessor.
      Specified by:
      dtoClass in interface FieldAccessor
      Returns:
      The parent DTO type
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object