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.collection.SynchronizedCollection;
  19. /**
  20. * Decorates another <code>Set</code> to synchronize its behaviour for a
  21. * multi-threaded environment.
  22. * <p>
  23. * Methods are synchronized, then forwarded to the decorated set.
  24. * <p>
  25. * This class is Serializable from Commons Collections 3.1.
  26. *
  27. * @since Commons Collections 3.0
  28. * @version $Revision: 1.5 $ $Date: 2004/06/03 22:02:13 $
  29. *
  30. * @author Stephen Colebourne
  31. */
  32. public class SynchronizedSet extends SynchronizedCollection implements Set {
  33. /** Serialization version */
  34. private static final long serialVersionUID = -8304417378626543635L;
  35. /**
  36. * Factory method to create a synchronized set.
  37. *
  38. * @param set the set to decorate, must not be null
  39. * @throws IllegalArgumentException if set is null
  40. */
  41. public static Set decorate(Set set) {
  42. return new SynchronizedSet(set);
  43. }
  44. //-----------------------------------------------------------------------
  45. /**
  46. * Constructor that wraps (not copies).
  47. *
  48. * @param set the set to decorate, must not be null
  49. * @throws IllegalArgumentException if set is null
  50. */
  51. protected SynchronizedSet(Set set) {
  52. super(set);
  53. }
  54. /**
  55. * Constructor that wraps (not copies).
  56. *
  57. * @param set the set to decorate, must not be null
  58. * @param lock the lock object to use, must not be null
  59. * @throws IllegalArgumentException if set is null
  60. */
  61. protected SynchronizedSet(Set set, Object lock) {
  62. super(set, lock);
  63. }
  64. /**
  65. * Gets the decorated set.
  66. *
  67. * @return the decorated set
  68. */
  69. protected Set getSet() {
  70. return (Set) collection;
  71. }
  72. }