Class DeepCloner.Builder

  • Enclosing class:
    DeepCloner

    public static class DeepCloner.Builder
    extends Object
    Builder for the DeepCloner helper class.
    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • build

        public DeepCloner build()
        Returns a DeepCloner initialized with the respective constructors and cloners.
        Returns:
      • constructor

        public <V> DeepCloner.Builder constructor​(Class<V> clazz,
                                                  Function<DeepCloner,​? extends V> constructor)
        Adds a method, often a constructor, that instantiates a record of type V.
        Type Parameters:
        V - Class or interface that would be instantiated by the given methods
        Parameters:
        clazz - Class or interface that would be instantiated by the given methods
        constructor - Function that creates a new instance of class V. If null, such a single-parameter constructor is not available.
        Returns:
        This builder.
      • delegateCreator

        public <V> DeepCloner.Builder delegateCreator​(Class<V> clazz,
                                                      DeepCloner.EntityFieldDelegateCreator<V> delegateCreator)
        Adds a method that instantiates an per-field delegate of type V.
        Type Parameters:
        V - Class or interface that would be instantiated by the given methods
        Parameters:
        clazz - Class or interface that would be instantiated by the given methods
        delegateCreator - Function that creates a new instance of class V. If null, such a single-parameter constructor is not available.
        Returns:
        This builder.
      • delegateCreator

        public <V> DeepCloner.Builder delegateCreator​(Class<V> clazz,
                                                      DeepCloner.DelegateCreator<V> delegateCreator)
        Adds a method, often a constructor, that instantiates a delegate of type V.
        Type Parameters:
        V - Class or interface that would be instantiated by the given methods
        Parameters:
        clazz - Class or interface that would be instantiated by the given methods
        delegateCreator - Function that creates a new instance of class V. If null, such a single-parameter constructor is not available.
        Returns:
        This builder.
      • cloner

        public <V> DeepCloner.Builder cloner​(Class<? extends V> clazz,
                                             DeepCloner.Cloner<?> cloner)
        Adds a method that copies (as in a deep copy) an object properties from one object to another
        Type Parameters:
        V - Class or interface whose instance would be copied over to another instance by the given cloner
        Parameters:
        clazz - Class or interface whose instance would be copied over to another instance by the given cloner
        cloner - A method for cloning with the following signature: V deepClone(V from, V to) which copies properties of an object from onto the object to. This function usually returns to
        Returns:
        This builder.
      • cloner

        public <V> DeepCloner.Builder cloner​(Class<? extends V> clazz,
                                             DeepCloner.Cloner<?> clonerWithId,
                                             DeepCloner.Cloner<?> clonerWithoutId)
        Adds a method that copies (as in a deep copy) an object properties from one object to another
        Type Parameters:
        V - Class or interface whose instance would be copied over to another instance by the given cloner
        Parameters:
        clazz - Class or interface whose instance would be copied over to another instance by the given cloner
        clonerWithId - A method for cloning with the following signature: V deepClone(V from, V to) which copies properties of an object from onto the object to. This function usually returns to
        Returns:
        This builder.
      • genericCloner

        public <V> DeepCloner.Builder genericCloner​(DeepCloner.Cloner<V> genericCloner)
        Adds a method that copies (as in a deep copy) an object properties to another object for any class that is not covered by a specific cloner set via #cloner(Class, BiFunction) method.
        Type Parameters:
        V - Class or interface whose instance would be copied over to another instance by the given cloner
        Parameters:
        genericCloner - A method for cloning which copies properties of an object onto another object. This function usually returns to
        Returns:
        This builder.