/** * Deep copies one object into another, this is primarily for copying between identical types of objects but * it can also handle copying between objects which are quite different, * this does not just do a reference copy of the values but actually creates new objects in the current classloader * * @param orig the original object to copy from * @param dest the object to copy the values to (must have the same fields with the same types) * @param maxDepth the number of objects to follow when traveling through the object and copying * the values from it, 0 means to only copy the simple values in the object, any objects will * be ignored and will end up as nulls, 1 means to follow the first objects found and copy all * of their simple values as well, and so forth * @param fieldNamesToSkip (optional) the names of fields to skip while cloning this object, * this only has an effect on the bottom level of the object, any fields found * on child objects will always be copied (if the maxDepth allows) * @param ignoreNulls if true then nulls are not copied and the destination retains the value it has, * if false then nulls are copied and the destination value will become a null if the original value is a null * @throws IllegalArgumentException if the copy cannot be completed because the objects to copy do not have matching fields or types */ public void deepCopy(Object orig, Object dest, int maxDepth, String[] fieldNamesToSkip, boolean ignoreNulls) { Set<String> skip = ArrayUtils.makeSetFromArray(fieldNamesToSkip); internalDeepCopy(orig, dest, maxDepth, skip, ignoreNulls, true); }
/** * Deep copies one object into another, this is primarily for copying between identical types of objects but * it can also handle copying between objects which are quite different, * this does not just do a reference copy of the values but actually creates new objects in the current classloader * * @param orig the original object to copy from * @param dest the object to copy the values to (must have the same fields with the same types) * @param maxDepth the number of objects to follow when traveling through the object and copying * the values from it, 0 means to only copy the simple values in the object, any objects will * be ignored and will end up as nulls, 1 means to follow the first objects found and copy all * of their simple values as well, and so forth * @param fieldNamesToSkip (optional) the names of fields to skip while cloning this object, * this only has an effect on the bottom level of the object, any fields found * on child objects will always be copied (if the maxDepth allows) * @param ignoreNulls if true then nulls are not copied and the destination retains the value it has, * if false then nulls are copied and the destination value will become a null if the original value is a null * @throws IllegalArgumentException if the copy cannot be completed because the objects to copy do not have matching fields or types */ public void deepCopy(Object orig, Object dest, int maxDepth, String[] fieldNamesToSkip, boolean ignoreNulls) { Set<String> skip = ArrayUtils.makeSetFromArray(fieldNamesToSkip); internalDeepCopy(orig, dest, maxDepth, skip, ignoreNulls, true); }
/** * Deep clone an object and all the values in it into a brand new object of the same type, * this will traverse the bean and will make new objects for all non-null values contained in the object * * @param <T> * @param object any java object, this can be a list, map, array, or any simple * object, it does not have to be a custom object or even a java bean, * also works with DynaBeans * @param maxDepth the number of objects to follow when traveling through the object and copying * the values from it, 0 means to only copy the simple values in the object, any objects will * be ignored and will end up as nulls, 1 means to follow the first objects found and copy all * of their simple values as well, and so forth * @param fieldNamesToSkip (optional) the names of fields to skip while cloning this object, * this only has an effect on the bottom level of the object, any fields found * on child objects will always be copied (if the maxDepth allows) * @return the cloned object */ @SuppressWarnings("unchecked") public <T> T deepClone(T object, int maxDepth, String[] fieldNamesToSkip) { Set<String> skip = ArrayUtils.makeSetFromArray(fieldNamesToSkip); T clone = (T) internalDeepClone(object, CopyDestination.ORIGINAL, maxDepth, skip, 0, true, false); return clone; }
/** * Deep clone an object and all the values in it into a brand new object of the same type, * this will traverse the bean and will make new objects for all non-null values contained in the object * * @param <T> * @param object any java object, this can be a list, map, array, or any simple * object, it does not have to be a custom object or even a java bean, * also works with DynaBeans * @param maxDepth the number of objects to follow when traveling through the object and copying * the values from it, 0 means to only copy the simple values in the object, any objects will * be ignored and will end up as nulls, 1 means to follow the first objects found and copy all * of their simple values as well, and so forth * @param fieldNamesToSkip (optional) the names of fields to skip while cloning this object, * this only has an effect on the bottom level of the object, any fields found * on child objects will always be copied (if the maxDepth allows) * @return the cloned object */ @SuppressWarnings("unchecked") public <T> T deepClone(T object, int maxDepth, String[] fieldNamesToSkip) { Set<String> skip = ArrayUtils.makeSetFromArray(fieldNamesToSkip); T clone = (T) internalDeepClone(object, CopyDestination.ORIGINAL, maxDepth, skip, 0, true, false); return clone; }
Set<String> skip = ArrayUtils.makeSetFromArray(fieldNamesToSkip); Object clone = internalDeepClone(object, CopyDestination.MAP, maxDepth, skip, 0, ignoreNulls, ignoreTransient); Map<String, Object> map = null;
Set<String> skip = ArrayUtils.makeSetFromArray(fieldNamesToSkip); Object clone = internalDeepClone(object, CopyDestination.MAP, maxDepth, skip, 0, ignoreNulls, ignoreTransient); Map<String, Object> map = null;