Interface Copyable<T>

  • Type Parameters:
    T - the generic type

    public interface Copyable<T>
    The Interface Copyable.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.springframework.util.ReflectionUtils.FieldFilter COPYABLE_FIELDS
      Pre-built FieldFilter that matches all non-static, non-final, non-Collection fields.
    • Field Detail

      • COPYABLE_FIELDS

        static final org.springframework.util.ReflectionUtils.FieldFilter COPYABLE_FIELDS
        Pre-built FieldFilter that matches all non-static, non-final, non-Collection fields.
    • Method Detail

      • copy

        default T copy()
        Make a deep copy of the object, with all new instances. Implementations should use apply(Object) to apply this values to the new instance. Default implementation returns null.
         @Override
         public Budget copy() {
                final Budget copy = new Budget();
                copy.apply(this);
                return copy;
         }
         
        Returns:
        a deep copy
      • apply

        default T apply​(T source)
        Apply values from source to this object. It should not handle lists, sets and other complicated things. The default implementation is based on ReflectionUtils.shallowCopyFieldState(Object, Object) but it only uses accessible fields and ignores Collections.
        Parameters:
        source - the source
        Returns:
        the t
      • copyList

        default <R extends Copyable<R>> List<R> copyList​(List<R> source,
                                                         Consumer<? super R> action)
        Utility method that makes a deep copy of Copyable elements.
        Type Parameters:
        R - the generic type
        Parameters:
        source - the source
        action - the action
        Returns:
        the list