Package org.apache.sis.internal.util
Class Cloner
java.lang.Object
org.apache.sis.internal.util.Cloner
Clones objects of arbitrary type using reflection methods. This is a workaround
for the lack of public
clone() method in the Cloneable interface.- Since:
- 0.3
- Version:
- 1.1
- Author:
- Martin Desruisseaux (Geomatys)
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Cloner
public Cloner()Creates a newClonerinstance which requires publicclone()method to be present. -
Cloner
public Cloner(boolean isCloneRequired) Creates a newClonerinstance.- Parameters:
isCloneRequired- whether aCloneNotSupportedExceptionshould be thrown if no publicclone()method is found.
-
-
Method Details
-
clone
Clones the given object. If the given object does not provide a publicclone()method, then there is a choice:- If
isCloneRequired(object)returnstrue(the default), then aCloneNotSupportedExceptionis thrown. - Otherwise the given object is returned.
- Parameters:
object- the object to clone, ornull.- Returns:
- a clone of the given object, or
nullifobjectwas null. - Throws:
CloneNotSupportedException- if the given object cannot be cloned.
- If
-
cloneIfPublic
Clones the given object if itsclone()method is public, or returns the same object otherwise. This method may be convenient when there is only one object to clone, otherwise instantiating a newClonerobject is more efficient.- Parameters:
object- the object to clone, ornull.- Returns:
- the given object (which may be
null) or a clone of the given object. - Throws:
CloneNotSupportedException- if the call toObject.clone()failed.- Since:
- 0.6
-