Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / lang / Cloneable.java @ 2608

History | View | Annotate | Download (2.14 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2021 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.lang;
25

    
26
/**
27
 * {@link java.lang.Cloneable} extension to define the
28
 * {@link java.lang.Cloneable#clone()} as a public method.
29
 *
30
 * @author gvSIG Team
31
 */
32
public interface Cloneable extends java.lang.Cloneable {
33

    
34
    public static Object cloneQuietly(Object x) {
35
        if (x instanceof Cloneable) {
36
            try {
37
                return ((Cloneable)x).clone();
38
            } catch (CloneNotSupportedException ex) {
39
                return null;
40
            }
41
        }
42
        return null;
43
    }
44

    
45
    public static Object cloneQuietly(Cloneable x) {
46
        if (x == null) {
47
            return null;
48
        }
49
        try {
50
            return x.clone();
51
        } catch (CloneNotSupportedException ex) {
52
            return null;
53
        }
54
    }
55

    
56
    /**
57
     * Creates a copy of the object.
58
     *
59
     * @return a copy of the object
60
     * @throws CloneNotSupportedException if the instance of the object cannot
61
     * be cloned. As this is extending {@link java.lang.Cloneable} so its sure
62
     * it implements it, so this exception may be used for problems on specific
63
     * object instances.
64
     * @see {@link Object#clone()}.
65
     */
66
    public Object clone() throws CloneNotSupportedException;
67

    
68
}