Class CopyUtils

java.lang.Object
io.github.bakedlibs.dough.collections.CopyUtils

public final class CopyUtils extends Object
Utilities for deep-copying collections, maps and arrays
Author:
md5sha256
  • Method Details

    • deepCopy

      public static <T> void deepCopy(@Nonnull Collection<T> source, @Nonnull UnaryOperator<T> cloningFunction, @Nonnull Collection<T> sink)
      Perform a deep copy of all the elements from a given Collection to another.

      If the source collection contains null elements, the cloning function should be able to handle null input. Additionally, the sink should also accept any values contained by the source collection, null or not.

      Type Parameters:
      T - The type of elements in the collections
      Parameters:
      source - The source of the elements
      cloningFunction - The function which clones the elements
      sink - The collection in which to copy to the cloned elements to
    • deepCopy

      @Nonnull public static <T, C extends Collection<T>> C deepCopy(@Nonnull Collection<T> source, @Nonnull UnaryOperator<T> cloningFunction, @Nonnull IntFunction<C> sinkSupplier)
      Perform a deep copy of all the elements from a given Collection to another.

      If the source collection contains null elements, the cloning function should be able to handle null input. Additionally, the sink supplied by the sink supplier should also accept any values contained by the source collection, null or not.

      Type Parameters:
      T - The type of elements in the collections
      C - The type of the returned collection
      Parameters:
      source - The source of the elements
      cloningFunction - The function which clones the elements
      sinkSupplier - The supplier which consumes the size of the source collection and supplies the collection to copy cloned elements to
    • deepCopy

      public static <K, V> void deepCopy(@Nonnull Map<K,V> source, @Nonnull UnaryOperator<V> cloningFunction, @Nonnull Map<K,V> sink)
      Perform a deep copy of all the elements from a given Map to another.

      If the source map contains null values, the cloning function should be able to handle null input. Additionally, the sink should also accept any keys and values contained by the source Map, null or not.

      Type Parameters:
      K - The type of keys in the maps
      V - The type of values in the maps
      Parameters:
      source - The source of the elements
      cloningFunction - The function which clones the elements
      sink - The map in which to copy to the cloned elements to
    • deepCopy

      @Nonnull public static <K, V, M extends Map<K, V>> M deepCopy(@Nonnull Map<K,V> source, @Nonnull UnaryOperator<V> cloningFunction, @Nonnull Supplier<M> sinkSupplier)
      Perform a deep copy of all the elements from a given Map to another.

      If the source map contains null values, the cloning function should be able to handle null input. Additionally, the sink should also accept any keys and values contained by the source Map, null or not.

      Type Parameters:
      K - The type of keys in the maps
      V - The type of values in the maps
      M - The type of the returned map
      Parameters:
      source - The source of the elements
      cloningFunction - The function which clones the elements
      sinkSupplier - The supplier which consumes the size of the source map and supplies the map to copy cloned elements to
    • deepCopy

      public static <K, V> void deepCopy(@Nonnull Map<K,V> source, @Nonnull UnaryOperator<V> cloningFunction)
      Perform a deep-clone transformation on all values in a given Map

      If the source map contains null values, the cloning function should be able to handle null input.

      Type Parameters:
      K - The type of keys in the map
      V - The type of values in the map
      Parameters:
      source - The source of the elements
      cloningFunction - The function which clones the elements
    • deepCopy

      public static <T> void deepCopy(@Nonnull T[] source, @Nonnull UnaryOperator<T> cloningFunction, @Nonnull T[] sink)
      Perform a deep copy of all the elements from a given array to another.

      If the source array contains null elements, the cloning function should be able to handle null input.

      Type Parameters:
      T - The type of elements in the arrays
      Parameters:
      source - The source of the elements
      cloningFunction - The function which clones the elements
      sink - The array in which to copy to the cloned elements to
    • deepCopy

      @Nonnull public static <T> T[] deepCopy(@Nonnull T[] source, @Nonnull UnaryOperator<T> cloningFunction, @Nonnull IntFunction<T[]> sinkSupplier)
      Perform a deep copy of all the elements from a given array to another.

      If the source array contains null elements, the cloning function should be able to handle null input.

      Type Parameters:
      T - The type of elements in the arrays
      Parameters:
      source - The source of the elements
      cloningFunction - The function which clones the elements
      sinkSupplier - The supplier which consumes the length of the source array and supplies the array to copy the cloned elements to