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