KickJava   Java API By Example, From Geeks To Geeks.

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


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.collection.SynchronizedCollection;
21
22 /**
23  * Decorates another <code>Set</code> to synchronize its behaviour for a
24  * multi-threaded environment.
25  * <p>
26  * Methods are synchronized, then forwarded to the decorated set.
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 SynchronizedSet extends SynchronizedCollection implements Set JavaDoc {
36
37     /** Serialization version */
38     private static final long serialVersionUID = -8304417378626543635L;
39
40     /**
41      * Factory method to create a synchronized set.
42      *
43      * @param set the set to decorate, must not be null
44      * @throws IllegalArgumentException if set is null
45      */

46     public static Set JavaDoc decorate(Set JavaDoc set) {
47         return new SynchronizedSet(set);
48     }
49     
50     //-----------------------------------------------------------------------
51
/**
52      * Constructor that wraps (not copies).
53      *
54      * @param set the set to decorate, must not be null
55      * @throws IllegalArgumentException if set is null
56      */

57     protected SynchronizedSet(Set JavaDoc set) {
58         super(set);
59     }
60
61     /**
62      * Constructor that wraps (not copies).
63      *
64      * @param set the set to decorate, must not be null
65      * @param lock the lock object to use, must not be null
66      * @throws IllegalArgumentException if set is null
67      */

68     protected SynchronizedSet(Set JavaDoc set, Object JavaDoc lock) {
69         super(set, lock);
70     }
71
72     /**
73      * Gets the decorated set.
74      *
75      * @return the decorated set
76      */

77     protected Set JavaDoc getSet() {
78         return (Set JavaDoc) collection;
79     }
80
81 }
82
Popular Tags