public static Object duplicate ( Object object , boolean deepCopy ) { if ( object == null ) return null ; if ( object instanceof Number ) return object ; if ( object instanceof String ) return object ; if ( object instanceof Date ) return ( ( Date ) object ) . clone ( ) ; if ( object instanceof Boolean ) return object ; RefBoolean before = new RefBooleanImpl ( ) ; try { Object copy = ThreadLocalDuplication . get ( object , before ) ; if ( copy != null ) { return copy ; } if ( object instanceof Collection ) return ( ( Collection ) object ) . duplicate ( deepCopy ) ; if ( object instanceof Duplicable ) return ( ( Duplicable ) object ) . duplicate ( deepCopy ) ; if ( object instanceof UDF ) return ( ( UDF ) object ) . duplicate ( ) ; if ( object instanceof List ) return duplicateList ( ( List ) object , deepCopy ) ; if ( object instanceof Map ) return duplicateMap ( ( Map ) object , deepCopy ) ; if ( object instanceof Serializable ) { try { String ser = JavaConverter . serialize ( ( Serializable ) object ) ; return JavaConverter . deserialize ( ser ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; } } } finally { if ( ! before . toBooleanValue ( ) ) ThreadLocalDuplication . reset ( ) ; } return object ; }
reference type value duplication