KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > set > TransformedSet


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
18 import java.util.Set JavaDoc;
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: 1.5 $ $Date: 2004/06/03 22:02:13 $
35  *
36  * @author Stephen Colebourne
37  */

38 public class TransformedSet extends TransformedCollection implements Set JavaDoc {
39
40     /** Serialization version */
41     private static final long serialVersionUID = 306127383500410386L;
42
43     /**
44      * Factory method to create a transforming set.
45      * <p>
46      * If there are any elements already in the set being decorated, they
47      * are NOT transformed.
48      *
49      * @param set the set to decorate, must not be null
50      * @param transformer the transformer to use for conversion, must not be null
51      * @throws IllegalArgumentException if set or transformer is null
52      */

53     public static Set JavaDoc decorate(Set JavaDoc set, Transformer transformer) {
54         return new TransformedSet(set, transformer);
55     }
56     
57     //-----------------------------------------------------------------------
58
/**
59      * Constructor that wraps (not copies).
60      * <p>
61      * If there are any elements already in the set being decorated, they
62      * are NOT transformed.
63      *
64      * @param set the set to decorate, must not be null
65      * @param transformer the transformer to use for conversion, must not be null
66      * @throws IllegalArgumentException if set or transformer is null
67      */

68     protected TransformedSet(Set JavaDoc set, Transformer transformer) {
69         super(set, transformer);
70     }
71
72 }
73
Popular Tags