public class CloneableBean extends Object implements Serializable, Cloneable
It works on all read/write properties, recursively. It support all primitive types, Strings, Collections, Cloneable objects and multi-dimensional arrays of any of them.
Modifier | Constructor and Description |
---|---|
protected |
CloneableBean()
Default constructor.
|
|
CloneableBean(Object obj)
Creates a CloneableBean to be used in a delegation pattern.
|
|
CloneableBean(Object obj,
Set<String> ignoreProperties)
Creates a CloneableBean to be used in a delegation pattern.
|
Modifier and Type | Method and Description |
---|---|
Object |
beanClone()
Makes a deep bean clone of the object passed in the constructor.
|
Object |
clone()
Makes a deep bean clone of the object.
|
protected CloneableBean()
To be used by classes extending CloneableBean only.
public CloneableBean(Object obj)
For example:
public class Foo implements Cloneable {
private CloneableBean cloneableBean;
public Foo() {
cloneableBean = new CloneableBean(this);
}
public Object clone() throws CloneNotSupportedException {
return cloneableBean.beanClone();
}
}
obj
- object bean to clone.public CloneableBean(Object obj, Set<String> ignoreProperties)
The property names in the ignoreProperties Set will not be copied into the cloned instance. This is useful for cases where the Bean has convenience properties (properties that are actually references to other properties or properties of properties). For example SyndFeed and SyndEntry beans have convenience properties, publishedDate, author, copyright and categories all of them mapped to properties in the DC Module.
obj
- object bean to clone.ignoreProperties
- properties to ignore when cloning.public Object clone() throws CloneNotSupportedException
To be used by classes extending CloneableBean. Although it works also for classes using CloneableBean in a delegation pattern, for correctness those classes should use the
clone
in class Object
CloneNotSupportedException
- thrown if the object bean could not be cloned.beanClone method.
public Object beanClone() throws CloneNotSupportedException
To be used by classes using CloneableBean in a delegation pattern,
CloneNotSupportedException
- thrown if the object bean could not be cloned.constructor.
Copyright © 2019. All rights reserved.