001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.collections.set; 018 019 import java.util.Set; 020 021 import org.apache.commons.collections.collection.SynchronizedCollection; 022 023 /** 024 * Decorates another <code>Set</code> to synchronize its behaviour for a 025 * multi-threaded environment. 026 * <p> 027 * Methods are synchronized, then forwarded to the decorated set. 028 * <p> 029 * This class is Serializable from Commons Collections 3.1. 030 * 031 * @since Commons Collections 3.0 032 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $ 033 * 034 * @author Stephen Colebourne 035 */ 036 public class SynchronizedSet extends SynchronizedCollection implements Set { 037 038 /** Serialization version */ 039 private static final long serialVersionUID = -8304417378626543635L; 040 041 /** 042 * Factory method to create a synchronized set. 043 * 044 * @param set the set to decorate, must not be null 045 * @throws IllegalArgumentException if set is null 046 */ 047 public static Set decorate(Set set) { 048 return new SynchronizedSet(set); 049 } 050 051 //----------------------------------------------------------------------- 052 /** 053 * Constructor that wraps (not copies). 054 * 055 * @param set the set to decorate, must not be null 056 * @throws IllegalArgumentException if set is null 057 */ 058 protected SynchronizedSet(Set set) { 059 super(set); 060 } 061 062 /** 063 * Constructor that wraps (not copies). 064 * 065 * @param set the set to decorate, must not be null 066 * @param lock the lock object to use, must not be null 067 * @throws IllegalArgumentException if set is null 068 */ 069 protected SynchronizedSet(Set set, Object lock) { 070 super(set, lock); 071 } 072 073 /** 074 * Gets the decorated set. 075 * 076 * @return the decorated set 077 */ 078 protected Set getSet() { 079 return (Set) collection; 080 } 081 082 }