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.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: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
32: *
33: * @author Stephen Colebourne
34: */
35: public class SynchronizedSet extends SynchronizedCollection implements
36: Set {
37:
38: /** Serialization version */
39: private static final long serialVersionUID = -8304417378626543635L;
40:
41: /**
42: * Factory method to create a synchronized set.
43: *
44: * @param set the set to decorate, must not be null
45: * @throws IllegalArgumentException if set is null
46: */
47: public static Set decorate(Set set) {
48: return new SynchronizedSet(set);
49: }
50:
51: //-----------------------------------------------------------------------
52: /**
53: * Constructor that wraps (not copies).
54: *
55: * @param set the set to decorate, must not be null
56: * @throws IllegalArgumentException if set is null
57: */
58: protected SynchronizedSet(Set set) {
59: super (set);
60: }
61:
62: /**
63: * Constructor that wraps (not copies).
64: *
65: * @param set the set to decorate, must not be null
66: * @param lock the lock object to use, must not be null
67: * @throws IllegalArgumentException if set is null
68: */
69: protected SynchronizedSet(Set set, Object lock) {
70: super (set, lock);
71: }
72:
73: /**
74: * Gets the decorated set.
75: *
76: * @return the decorated set
77: */
78: protected Set getSet() {
79: return (Set) collection;
80: }
81:
82: }
|