Package com.helger.base.clone
Class CloneHelper
java.lang.Object
com.helger.base.clone.CloneHelper
Helper class for cloning objects.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic <DATATYPE> @Nullable DATATYPEgetClonedValue(@Nullable DATATYPE aObject) Get a clone (= deep copy) of the passed value.static <DATATYPE extends ICloneable<DATATYPE>>
@Nullable DATATYPEgetCloneIfNotNull(@Nullable DATATYPE aObject) Get a clone (= deep copy) of the passed value for all objects implementingICloneable.
-
Method Details
-
getClonedValue
public static <DATATYPE> @Nullable DATATYPE getClonedValue(@Nullable DATATYPE aObject) Get a clone (= deep copy) of the passed value. The following things are tried for cloning:- If the object is immutable, it is returned as is (if it is a primitive type or marked with
the
Immutableannotation. - If the object implements
ICloneableit is invoked. - If the object implements
Cloneableit is invoked. - If a copy constructor (a constructor taking one argument of the same class as it declares)
nullis returned.- Type Parameters:
DATATYPE- The source and return type- Parameters:
aObject- The object to be copied.- Returns:
nullif the passed value isnullor if no cloning could be performed.
- If the object is immutable, it is returned as is (if it is a primitive type or marked with
the
-
getCloneIfNotNull
public static <DATATYPE extends ICloneable<DATATYPE>> @Nullable DATATYPE getCloneIfNotNull(@Nullable DATATYPE aObject) Get a clone (= deep copy) of the passed value for all objects implementingICloneable.- Type Parameters:
DATATYPE- The data type to be cloned- Parameters:
aObject- The object to be copied. May benull.- Returns:
nullif the passed value isnullor a clone of the object.
-