public class CopyContext extends Object
Constructor and Description |
---|
CopyContext()
Initializes a new instance.
|
Modifier and Type | Method and Description |
---|---|
<T> void |
addObjectMapping(T oldObject,
T newObject)
Adds a mapping between an old object reference and a new one.
|
void |
clearObjectMapping()
Clears the list of mappings that has been created with calls to
CopyContext.addObjectMapping(T, T) . |
protected <T> T |
clone(T oldObject)
Copies the specified object using the
ICloneWithContext interface or the
ICloneable interface, with a preference on
ICloneWithContext . |
<T> T |
cloneIfNotMapped(T oldObject)
Looks for a mapping for this object that was added with
CopyContext.addObjectMapping(T, T) . |
<T> T |
getObjectMapping(T oldObject)
Gets the mapping for the specified object.
|
<T> T |
updateReference(T oldObject)
Updates a given reference, returning a reference to use in its place.
|
public <T> T cloneIfNotMapped(T oldObject)
CopyContext.addObjectMapping(T, T)
. If one is found,
the object to which the specified one is mapped is returned. If one is not found, this method clones the
given object by calling CopyContext.clone(T)
. Derived classes can override this default behavior.T
- The type of the object to clone.oldObject
- The old object reference for which to look for a mapping or clone.IllegalStateException
- The object does not implement ICloneWithContext
or
ICloneable
.@Nonnull protected final <T> T clone(@Nonnull T oldObject)
ICloneWithContext
interface or the
ICloneable
interface, with a preference on
ICloneWithContext
.T
- The type of the object to clone.oldObject
- The object to clone.ArgumentNullException
- Thrown when oldObject
is null.IllegalStateException
- The object does not implement ICloneWithContext
or ICloneable
.public final <T> void addObjectMapping(@Nonnull T oldObject, @Nonnull T newObject)
CopyContext.updateReference(T)
will substitute
newObject
everywhere it encounters oldObject
.T
- The type of object to map.oldObject
- The old object reference.newObject
- The new object reference.public final <T> T getObjectMapping(T oldObject)
T
- The type of object to map.oldObject
- The old object reference for which to look for a mapping.public final void clearObjectMapping()
CopyContext.addObjectMapping(T, T)
. This is
useful if you want to reuse a CopyContext
instance for a separate copy operation.public <T> T updateReference(T oldObject)
CopyContext.addObjectMapping(T, T)
. If one is
found, the object to which the specified one is mapped is returned. If one is not found, this method
returns the object that was passed to it. Derived classes can override this default behavior.T
- The type of the object reference.oldObject
- The old reference to update.