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. import java.io.Serializable;
  18. import org.apache.commons.collections.Transformer;
  19. /**
  20. * Transformer implementation that returns a clone of the input object.
  21. * <p>
  22. * Clone is performed using <code>PrototypeFactory.getInstance(input).create()</code>.
  23. *
  24. * @since Commons Collections 3.0
  25. * @version $Revision: 1.6 $ $Date: 2004/05/16 11:36:31 $
  26. *
  27. * @author Stephen Colebourne
  28. */
  29. public class CloneTransformer implements Transformer, Serializable {
  30. /** Serial version UID */
  31. static final long serialVersionUID = -8188742709499652567L;
  32. /** Singleton predicate instance */
  33. public static final Transformer INSTANCE = new CloneTransformer();
  34. /**
  35. * Factory returning the singleton instance.
  36. *
  37. * @return the singleton instance
  38. * @since Commons Collections 3.1
  39. */
  40. public static Transformer getInstance() {
  41. return INSTANCE;
  42. }
  43. /**
  44. * Constructor
  45. */
  46. private CloneTransformer() {
  47. super();
  48. }
  49. /**
  50. * Transforms the input to result by cloning it.
  51. *
  52. * @param input the input object to transform
  53. * @return the transformed result
  54. */
  55. public Object transform(Object input) {
  56. if (input == null) {
  57. return null;
  58. }
  59. return PrototypeFactory.getInstance(input).create();
  60. }
  61. }