Class TwoPhaseObjectCopier<T>

java.lang.Object
io.github.sugarcubes.cloner.TwoPhaseObjectCopier<T>
All Implemented Interfaces:
ObjectCopier<T>

public abstract class TwoPhaseObjectCopier<T> extends Object implements ObjectCopier<T>
Two-phase copier.
  • Constructor Details

    • TwoPhaseObjectCopier

      public TwoPhaseObjectCopier()
  • Method Details

    • copy

      public T copy(T original, CopyContext context) throws Exception
      Description copied from interface: ObjectCopier
      Creates a copy of the original object. The implementation MUST call CopyContext.register(Object) method.
      Specified by:
      copy in interface ObjectCopier<T>
      Parameters:
      original - original object
      context - copying context or null if the copier is trivial
      Returns:
      copy result
      Throws:
      Exception - if something went wrong
    • allocate

      public abstract T allocate(T original) throws Exception
      The first phase of copying. Creates an "empty" copy of the original object.
      Parameters:
      original - original object
      Returns:
      clone
      Throws:
      Exception - if something went wrong
    • deepCopy

      public abstract void deepCopy(T original, T clone, CopyContext context) throws Exception
      The second phase of copying, copies the inner state from the original object into the clone.
      Parameters:
      original - original object
      clone - clone
      context - copying context
      Throws:
      Exception - if something went wrong