KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > functors > CloneTransformer


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.functors;
17
18 import java.io.Serializable JavaDoc;
19
20 import org.apache.commons.collections.Transformer;
21
22 /**
23  * Transformer implementation that returns a clone of the input object.
24  * <p>
25  * Clone is performed using <code>PrototypeFactory.getInstance(input).create()</code>.
26  *
27  * @since Commons Collections 3.0
28  * @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
29  *
30  * @author Stephen Colebourne
31  */

32 public class CloneTransformer implements Transformer, Serializable JavaDoc {
33
34     /** Serial version UID */
35     static final long serialVersionUID = -8188742709499652567L;
36
37     /** Singleton predicate instance */
38     public static final Transformer INSTANCE = new CloneTransformer();
39
40     /**
41      * Factory returning the singleton instance.
42      *
43      * @return the singleton instance
44      * @since Commons Collections 3.1
45      */

46     public static Transformer getInstance() {
47         return INSTANCE;
48     }
49
50     /**
51      * Constructor
52      */

53     private CloneTransformer() {
54         super();
55     }
56
57     /**
58      * Transforms the input to result by cloning it.
59      *
60      * @param input the input object to transform
61      * @return the transformed result
62      */

63     public Object JavaDoc transform(Object JavaDoc input) {
64         if (input == null) {
65             return null;
66         }
67         return PrototypeFactory.getInstance(input).create();
68     }
69
70 }
71
Popular Tags