001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.lib.util.concurrent;
020:
021: import java.io.Serializable;
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.Set;
025:
026: import org.apache.commons.collections.set.MapBackedSet;
027:
028: /**
029: * A concurrent set.
030: *
031: * @author Abe White
032: * @nojavadoc
033: */
034: public class ConcurrentHashSet implements Set, Serializable {
035:
036: private static final Object DUMMY_VAL = new Object();
037:
038: private final Set _set;
039:
040: /**
041: * Construct a set with the given reference type.
042: */
043: public ConcurrentHashSet() {
044: _set = MapBackedSet
045: .decorate(new ConcurrentHashMap(), DUMMY_VAL);
046: }
047:
048: public boolean add(Object obj) {
049: return _set.add(obj);
050: }
051:
052: public boolean addAll(Collection coll) {
053: return _set.addAll(coll);
054: }
055:
056: public void clear() {
057: _set.clear();
058: }
059:
060: public boolean contains(Object obj) {
061: return _set.contains(obj);
062: }
063:
064: public boolean containsAll(Collection coll) {
065: return _set.containsAll(coll);
066: }
067:
068: public boolean isEmpty() {
069: return _set.isEmpty();
070: }
071:
072: public Iterator iterator() {
073: return _set.iterator();
074: }
075:
076: public boolean remove(Object obj) {
077: return _set.remove(obj);
078: }
079:
080: public boolean removeAll(Collection coll) {
081: return _set.removeAll(coll);
082: }
083:
084: public boolean retainAll(Collection coll) {
085: return _set.retainAll(coll);
086: }
087:
088: public int size() {
089: return _set.size();
090: }
091:
092: public Object[] toArray() {
093: return _set.toArray();
094: }
095:
096: public Object[] toArray(Object[] arr) {
097: return _set.toArray(arr);
098: }
099:
100: public int hashCode() {
101: return _set.hashCode();
102: }
103:
104: public boolean equals(Object obj) {
105: if (this == obj)
106: return true;
107: if (obj instanceof ConcurrentHashSet)
108: obj = ((ConcurrentHashSet) obj)._set;
109: return _set.equals(obj);
110: }
111: }
|