Class FieldsModel<T>

java.lang.Object
io.github.sugarcubes.cloner.spi.FieldsModel<T>
Type Parameters:
T - type

public final class FieldsModel<T> extends Object
Low-level model of a type whose instances are created without constructor and whose state is its fields. Knows how to allocate an instance and to read and write the fields declared by the type itself; what and how to copy is decided by the caller.
  • Constructor Details

    • FieldsModel

      public FieldsModel(Class<T> type, Reflection reflection, InstanceAllocatorFactory allocators, FieldAdapterFactory adapters)
      Creates the model of the type.
      Parameters:
      type - type
      reflection - reflection to list fields
      allocators - instance allocator factory
      adapters - field adapter factory
  • Method Details

    • getType

      public Class<T> getType()
      Returns the type.
      Returns:
      type
    • getAllocator

      public Optional<InstanceAllocator<T>> getAllocator()
      Returns allocator of instances.
      Returns:
      allocator or empty if no allocator supports the type (e.g. an abstract class)
    • getFields

      public Field[] getFields()
      Returns instance fields declared by the type itself, without fields of super types.
      Returns:
      fields
    • adapter

      public Optional<FieldAdapter> adapter(Field field)
      Creates an adapter which reads and writes the field.
      Parameters:
      field - one of getFields()
      Returns:
      field adapter, or empty if the field cannot be accessed