01: /*
02: * Copyright 2001-2006 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
19:
20: import org.apache.commons.collections.Transformer;
21:
22: /**
23: * Transformer implementation that returns the result of calling
24: * <code>String.valueOf</code> on the input object.
25: *
26: * @since Commons Collections 3.0
27: * @version $Revision: 405927 $ $Date: 2006-05-12 23:57:03 +0100 (Fri, 12 May 2006) $
28: *
29: * @author Stephen Colebourne
30: */
31: public final class StringValueTransformer implements Transformer,
32: Serializable {
33:
34: /** Serial version UID */
35: private static final long serialVersionUID = 7511110693171758606L;
36:
37: /** Singleton predicate instance */
38: public static final Transformer INSTANCE = new StringValueTransformer();
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: * Restricted constructor.
52: */
53: private StringValueTransformer() {
54: super ();
55: }
56:
57: /**
58: * Transforms the input to result by calling <code>String.valueOf</code>.
59: *
60: * @param input the input object to transform
61: * @return the transformed result
62: */
63: public Object transform(Object input) {
64: return String.valueOf(input);
65: }
66:
67: }
|