Class CloneUtil



  • public class CloneUtil
    extends java.lang.Object
    A utility class for clone operations.
    Since:
    1.0.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T deepClone​(T objectToBeClonned)  
      static <T> T deepCloneOnlyIfContains​(T objectToBeClonned, java.util.List<T> objects)
      clones only if objects contains the given objectToBeClonned, otherwise returns the same object.
      static <T> T deepCloneOnlyIfContains​(T objectToBeClonned, java.util.Set<T> objects)
      clones only if objects contains the given objectToBeClonned, otherwise returns the same object.
      static <T> T deepCloneOnlyIfContains​(T objectToBeClonned, T[] objects)
      clones only if objects contains the given objectToBeClonned, otherwise returns the same object.
      static <T> T deepCloneOnlyIfDoesNotContain​(T objectToBeClonned, java.util.List<T> objects)
      clones only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object.
      static <T> T deepCloneOnlyIfDoesNotContain​(T objectToBeClonned, java.util.Set<T> objects)
      clones only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object.
      static <T> T deepCloneOnlyIfDoesNotContain​(T objectToBeClonned, T[] objects)
      clones only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • deepCloneOnlyIfContains

        public static <T> T deepCloneOnlyIfContains​(T objectToBeClonned,
                                                    T[] objects)
                                             throws java.lang.CloneNotSupportedException
        clones only if objects contains the given objectToBeClonned, otherwise returns the same object.
        Parameters:
        objectToBeClonned - from which a new object will be cloned. null will be returned for null value.
        objects - to check if it contains objectToBeClonned.
        Returns:
        the new cloned object only if objects contains the given objectToBeClonned, otherwise returns the same object. If objectToBeClonned is null then returns null. If objects is null then objectToBeClonned will be returned.
        Throws:
        java.lang.CloneNotSupportedException
        Since:
        1.0.0
      • deepCloneOnlyIfContains

        public static <T> T deepCloneOnlyIfContains​(T objectToBeClonned,
                                                    java.util.List<T> objects)
                                             throws java.lang.CloneNotSupportedException
        clones only if objects contains the given objectToBeClonned, otherwise returns the same object.
        Parameters:
        objectToBeClonned - from which a new object will be cloned. null will be returned for null value.
        objects - to check if it contains objectToBeClonned.
        Returns:
        the new cloned object only if objects contains the given objectToBeClonned, otherwise returns the same object. If objectToBeClonned is null then returns null. If objects is null then objectToBeClonned will be returned.
        Throws:
        java.lang.CloneNotSupportedException
        Since:
        1.0.0
      • deepCloneOnlyIfContains

        public static <T> T deepCloneOnlyIfContains​(T objectToBeClonned,
                                                    java.util.Set<T> objects)
                                             throws java.lang.CloneNotSupportedException
        clones only if objects contains the given objectToBeClonned, otherwise returns the same object.
        Parameters:
        objectToBeClonned - from which a new object will be cloned. null will be returned for null value.
        objects - to check if it contains objectToBeClonned.
        Returns:
        the new cloned object only if objects contains the given objectToBeClonned, otherwise returns the same object. If objectToBeClonned is null then returns null. If objects is null then objectToBeClonned will be returned.
        Throws:
        java.lang.CloneNotSupportedException
        Since:
        1.0.0
      • deepCloneOnlyIfDoesNotContain

        public static <T> T deepCloneOnlyIfDoesNotContain​(T objectToBeClonned,
                                                          T[] objects)
                                                   throws java.lang.CloneNotSupportedException
        clones only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object.
        Parameters:
        objectToBeClonned - from which a new object will be cloned. null will be returned for null value.
        objects - to check if it doesn't contain objectToBeClonned.
        Returns:
        the new cloned object only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object. If objectToBeClonned is null then returns null. If objects is null then the cloned object will be returned.
        Throws:
        java.lang.CloneNotSupportedException
        Since:
        1.0.0
      • deepCloneOnlyIfDoesNotContain

        public static <T> T deepCloneOnlyIfDoesNotContain​(T objectToBeClonned,
                                                          java.util.List<T> objects)
                                                   throws java.lang.CloneNotSupportedException
        clones only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object.
        Parameters:
        objectToBeClonned - from which a new object will be cloned. null will be returned for null value.
        objects - to check if it doesn't contain objectToBeClonned.
        Returns:
        the new cloned object only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object. If objectToBeClonned is null then returns null. If objects is null then the cloned object will be returned.
        Throws:
        java.lang.CloneNotSupportedException
        Since:
        1.0.0
      • deepCloneOnlyIfDoesNotContain

        public static <T> T deepCloneOnlyIfDoesNotContain​(T objectToBeClonned,
                                                          java.util.Set<T> objects)
                                                   throws java.lang.CloneNotSupportedException
        clones only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object.
        Parameters:
        objectToBeClonned - from which a new object will be cloned. null will be returned for null value.
        objects - to check if it doesn't contain objectToBeClonned.
        Returns:
        the new cloned object only if objects doesn't contain the given objectToBeClonned, otherwise returns the same object. If objectToBeClonned is null then returns null. If objects is null then the cloned object will be returned.
        Throws:
        java.lang.CloneNotSupportedException
        Since:
        1.0.0
      • deepClone

        public static <T> T deepClone​(T objectToBeClonned)
                               throws java.lang.CloneNotSupportedException
        Parameters:
        objectToBeClonned - from which a new object will be cloned. null will be returned for null value.
        Returns:
        the newly cloned object or if objectToBeClonned is null.
        Throws:
        java.lang.CloneNotSupportedException
        Since:
        1.0.0