001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.util;
027:
028: import java.util.Collection;
029: import java.util.Iterator;
030: import java.util.Set;
031:
032: /**
033: * Wraps a Set disabling all mutator methods.
034: * @deprecated Use java.util.Collections.unmodifiableSet() method
035: **/
036: public class ReadOnlySet implements Set {
037: private Set inner;
038:
039: /**
040: * @deprecated Use java.util.Collections.unmodifiableSet() method
041: **/
042: public ReadOnlySet(Set s) {
043: inner = s;
044: }
045:
046: // Accessors
047:
048: public int size() {
049: return inner.size();
050: }
051:
052: public boolean isEmpty() {
053: return inner.isEmpty();
054: }
055:
056: public boolean contains(Object o) {
057: return inner.contains(o);
058: }
059:
060: public boolean containsAll(Collection c) {
061: return inner.containsAll(c);
062: }
063:
064: public Iterator iterator() {
065: return new Iterator() {
066: Iterator it = inner.iterator();
067:
068: public boolean hasNext() {
069: return it.hasNext();
070: }
071:
072: public Object next() {
073: return it.next();
074: }
075:
076: public void remove() {
077: throw new UnsupportedOperationException(
078: "ReadOnlySet: remove disallowed");
079: }
080: };
081: }
082:
083: public boolean equals(Object o) {
084: return inner.equals(o);
085: }
086:
087: public int hashCode() {
088: return inner.hashCode();
089: }
090:
091: public Object[] toArray() {
092: return inner.toArray();
093: }
094:
095: public Object[] toArray(Object[] a) {
096: return inner.toArray(a);
097: }
098:
099: // Mutators
100:
101: public boolean add(Object o) {
102: throw new UnsupportedOperationException(
103: "ReadOnlySet: add disallowed");
104: }
105:
106: public boolean remove(Object o) {
107: throw new UnsupportedOperationException(
108: "ReadOnlySet: remove disallowed");
109: }
110:
111: public boolean addAll(Collection c) {
112: throw new UnsupportedOperationException(
113: "ReadOnlySet: addAll disallowed");
114: }
115:
116: public boolean retainAll(Collection c) {
117: throw new UnsupportedOperationException(
118: "ReadOnlySet: retainAll disallowed");
119: }
120:
121: public boolean removeAll(Collection c) {
122: throw new UnsupportedOperationException(
123: "ReadOnlySet: removeAll disallowed");
124: }
125:
126: public void clear() {
127: throw new UnsupportedOperationException(
128: "ReadOnlySet: clear disallowed");
129: }
130: }
|