Class PropertyAccessor

java.lang.Object
org.litebridge.tracking.PropertyAccessor
All Implemented Interfaces:
FieldAccessor

public final class PropertyAccessor extends Object implements FieldAccessor
Property-based FieldAccessor implementation.

A concrete implementation of the FieldAccessor interface that provides access to a property of a data transfer object (DTO) using JavaBeans PropertyDescriptor.

This class allows retrieval and manipulation of a property’s value, as well as access to its metadata, such as name, type, and declaring class.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PropertyAccessor(Field field, MethodHandles.Lookup lookup, ClassFieldAccessorCache classFieldAccessorCache)
    Constructs a new PropertyAccessor for the specified field.
  • 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.litebridge.tracking.FieldAccessor

    genericType
  • Constructor Details

    • PropertyAccessor

      public PropertyAccessor(Field field, MethodHandles.Lookup lookup, ClassFieldAccessorCache classFieldAccessorCache)
      Constructs a new PropertyAccessor for the specified field.
      Parameters:
      field - the field to access
      lookup - the lookup to use for unreflecting the field
      classFieldAccessorCache - the cache to use for generic type information
  • 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