Class FieldCloner

java.lang.Object
com.comphenix.protocol.reflect.cloning.FieldCloner
All Implemented Interfaces:
Cloner

public class FieldCloner extends Object implements Cloner
Represents a class capable of cloning objects by deeply copying its fields.
  • Field Details

  • Constructor Details

    • FieldCloner

      public FieldCloner(Cloner defaultCloner, InstanceProvider instanceProvider)
      Constructs a field cloner that copies objects by reading and writing the internal fields directly.
      Parameters:
      defaultCloner - - the default cloner used while copying fields.
      instanceProvider - - used to construct new, empty copies of a given type.
  • Method Details

    • defaultTransform

      protected void defaultTransform(StructureModifier<Object> modifierSource, StructureModifier<Object> modifierDest, Cloner defaultCloner, int fieldIndex)
      Default implementation of the field transform. Applies a clone operation before a field value is written.
      Parameters:
      modifierSource - - modifier for the original object.
      modifierDest - - modifier for the new cloned object.
      defaultCloner - - cloner to use.
      fieldIndex - - the current field index.
    • canClone

      public boolean canClone(Object source)
      Description copied from interface: Cloner
      Determine whether the current cloner can clone the given object.
      Specified by:
      canClone in interface Cloner
      Parameters:
      source - - the object that is being considered.
      Returns:
      TRUE if this cloner can actually clone the given object, FALSE otherwise.
    • clone

      public Object clone(Object source)
      Description copied from interface: Cloner
      Perform the clone.

      This method should never be called unless a corresponding Cloner.canClone(Object) returns TRUE.

      Specified by:
      clone in interface Cloner
      Parameters:
      source - - the value to clone.
      Returns:
      A cloned value.
    • getDefaultCloner

      public Cloner getDefaultCloner()
      Retrieve the default cloner used to clone the content of each field.
      Returns:
      Cloner used to clone fields.
    • getInstanceProvider

      public InstanceProvider getInstanceProvider()
      Retrieve the instance provider this cloner is using to create new, empty classes.
      Returns:
      The instance provider in use.