includes/org/jopendocument/util/CopyUtils.java
@SuppressWarnings("unchecked")
    public static final <E> E copy(E object) {
        if (object == null)
            return null;

        if (object instanceof Cloneable) {
            final Method m;
            try {
                m = object.getClass().getMethod("clone");
            } catch (NoSuchMethodException e) {
                throw ExceptionUtils.createExn(IllegalStateException.class, "Cloneable w/o clone()", e);
            }
            try {
                return (E) m.invoke(object);
            } catch (Exception e) {
                throw ExceptionUtils.createExn(IllegalStateException.class, "clone() failed", e);
            }
        } else {
            try {
                return (E) object.getClass().getConstructor(new Class[] { object.getClass() }).newInstance(new Object[] { object });
            } catch (Exception e) {
                throw ExceptionUtils.createExn(IllegalStateException.class, "Copy constructor failed", e);
            }
        }
    }
/**
     * Copy the passed object. First tries to clone() it, otherwise tries with a copy constructor.
     * 
     * @param <E> the type of object to be copied.
     * @param object the object to be copied, can be <code>null</code>.
     * @return a copy of <code>object</code>, or <code>null</code> if object was
     *         <code>null</code>.
     * @throws IllegalStateException if the object can't be copied.
     */
Copy the passed object. First tries to clone() it, otherwise tries with a copy constructor.

@param  the type of object to be copied.
@param object the object to be copied, can be null.
@return a copy of object, or null if object was
null.
@throws IllegalStateException if the object can't be copied.
Copy the passed object . First tries to clone () it otherwise tries with a copy constructor . @param the type of object to be copied . @param object the object to be copied can be null . @return a copy of object or null if object was null . @throws IllegalStateException if the object can ' t be copied .
@SuppressWarnings("unchecked")
    public static final <E> E copy(E object) {
        if (object == null)
            return null;
        if (object instanceof Cloneable) {
            final Method m;
            try {
                m = object.getClass().getMethod("clone");
            } catch (NoSuchMethodException e) {
                throw ExceptionUtils.createExn(IllegalStateException.class, "Cloneable w/o clone()", e);
            }
            try {
                return (E) m.invoke(object);
            } catch (Exception e) {
                throw ExceptionUtils.createExn(IllegalStateException.class, "clone() failed", e);
            }
        } else {
            try {
                return (E) object.getClass().getConstructor(new Class[] { object.getClass() }).newInstance(new Object[] { object });
            } catch (Exception e) {
                throw ExceptionUtils.createExn(IllegalStateException.class, "Copy constructor failed", e);
            }
        }
    }
@ SuppressWarnings ( "unchecked" ) public static final < E > E copy ( E object ) { if ( object == null ) return null ; if ( object instanceof Cloneable ) { final Method m ; try { m = object . getClass ( ) . getMethod ( "clone" ) ; } catch ( NoSuchMethodException e ) { throw ExceptionUtils . createExn ( IllegalStateException . class , "Cloneable w/o clone()" , e ) ; } try { return ( E ) m . invoke ( object ) ; } catch ( Exception e ) { throw ExceptionUtils . createExn ( IllegalStateException . class , "clone() failed" , e ) ; } } else { try { return ( E ) object . getClass ( ) . getConstructor ( new Class [ ] { object . getClass ( ) } ) . newInstance ( new Object [ ] { object } ) ; } catch ( Exception e ) { throw ExceptionUtils . createExn ( IllegalStateException . class , "Copy constructor failed" , e ) ; } } }
Copy the passed object.
Copy the passed object .