Class FieldAccessorChain

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

public final class FieldAccessorChain extends Object implements FieldAccessor
Represents a chain of FieldAccessor instances, allowing the traversal and manipulation of nested fields of a data transfer object (DTO).

This class provides mechanisms to navigate nested structures while enabling read/write access to the chained fields.

  • Constructor Details

    • FieldAccessorChain

      public FieldAccessorChain(FieldAccessor parent, String fieldPath, ClassFieldAccessorCache classFieldAccessorCache)
      Constructs a new FieldAccessorChain.
      Parameters:
      parent - the parent field accessor.
      fieldPath - the field path.
      classFieldAccessorCache - the field accessor cache.
  • Method Details

    • fieldPath

      public String fieldPath()
      Returns the field path.
      Returns:
      the field path.
    • fieldAccessors

      public List<FieldAccessor> fieldAccessors()
      Returns the field accessors.
      Returns:
      the field accessors.
    • subChain

      public FieldAccessorChain subChain()
      Returns a sub-chain of this field accessor chain.
      Returns:
      a sub-chain of this field accessor chain.
    • add

      public FieldAccessorChain add(FieldAccessor fieldAccessor)
      Adds a field accessor to the chain.
      Parameters:
      fieldAccessor - the field accessor to add.
      Returns:
      this field accessor chain.
    • isLast

      public boolean isLast(FieldAccessor fieldAccessor)
      Returns true if the given field accessor is the last one in the chain.
      Parameters:
      fieldAccessor - the field accessor to check.
      Returns:
      true if the given field accessor is the last one in the chain.
    • 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 @Nullable 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