1. /*
  2. * Copyright 2003-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.set;
  17. import java.util.Set;
  18. import org.apache.commons.collections.Transformer;
  19. import org.apache.commons.collections.collection.TransformedCollection;
  20. /**
  21. * Decorates another <code>Set</code> to transform objects that are added.
  22. * <p>
  23. * The add methods are affected by this class.
  24. * Thus objects must be removed or searched for using their transformed form.
  25. * For example, if the transformation converts Strings to Integers, you must
  26. * use the Integer form to remove objects.
  27. * <p>
  28. * This class is Serializable from Commons Collections 3.1.
  29. *
  30. * @since Commons Collections 3.0
  31. * @version $Revision: 1.5 $ $Date: 2004/06/03 22:02:13 $
  32. *
  33. * @author Stephen Colebourne
  34. */
  35. public class TransformedSet extends TransformedCollection implements Set {
  36. /** Serialization version */
  37. private static final long serialVersionUID = 306127383500410386L;
  38. /**
  39. * Factory method to create a transforming set.
  40. * <p>
  41. * If there are any elements already in the set being decorated, they
  42. * are NOT transformed.
  43. *
  44. * @param set the set to decorate, must not be null
  45. * @param transformer the transformer to use for conversion, must not be null
  46. * @throws IllegalArgumentException if set or transformer is null
  47. */
  48. public static Set decorate(Set set, Transformer transformer) {
  49. return new TransformedSet(set, transformer);
  50. }
  51. //-----------------------------------------------------------------------
  52. /**
  53. * Constructor that wraps (not copies).
  54. * <p>
  55. * If there are any elements already in the set being decorated, they
  56. * are NOT transformed.
  57. *
  58. * @param set the set to decorate, must not be null
  59. * @param transformer the transformer to use for conversion, must not be null
  60. * @throws IllegalArgumentException if set or transformer is null
  61. */
  62. protected TransformedSet(Set set, Transformer transformer) {
  63. super(set, transformer);
  64. }
  65. }