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:
031: /**
032: * Wraps a Set disabling all mutator methods.
033: * @deprecated Use java.util.Collections.unmodifiableCollection() method
034: **/
035: public class ReadOnlyCollection implements Collection {
036: private Collection inner;
037:
038: /**
039: * @deprecated Use java.util.Collections.unmodifiableCollection() method
040: **/
041: public ReadOnlyCollection(Collection s) {
042: inner = s;
043: }
044:
045: // Accessors
046:
047: public int size() {
048: return inner.size();
049: }
050:
051: public boolean isEmpty() {
052: return inner.isEmpty();
053: }
054:
055: public boolean contains(Object o) {
056: return inner.contains(o);
057: }
058:
059: public boolean containsAll(Collection c) {
060: return inner.containsAll(c);
061: }
062:
063: public Iterator iterator() {
064: return new Iterator() {
065: Iterator it = inner.iterator();
066:
067: public boolean hasNext() {
068: return it.hasNext();
069: }
070:
071: public Object next() {
072: return it.next();
073: }
074:
075: public void remove() {
076: throw new UnsupportedOperationException(
077: "ReadOnlyCollection: remove disallowed");
078: }
079: };
080: }
081:
082: public boolean equals(Object o) {
083: return inner.equals(o);
084: }
085:
086: public int hashCode() {
087: return inner.hashCode();
088: }
089:
090: public Object[] toArray() {
091: return inner.toArray();
092: }
093:
094: public Object[] toArray(Object[] a) {
095: return inner.toArray(a);
096: }
097:
098: // Mutators
099:
100: public boolean add(Object o) {
101: throw new UnsupportedOperationException(
102: "ReadOnlyCollection: add disallowed");
103: }
104:
105: public boolean remove(Object o) {
106: throw new UnsupportedOperationException(
107: "ReadOnlyCollection: remove disallowed");
108: }
109:
110: public boolean addAll(Collection c) {
111: throw new UnsupportedOperationException(
112: "ReadOnlyCollection: addAll disallowed");
113: }
114:
115: public boolean retainAll(Collection c) {
116: throw new UnsupportedOperationException(
117: "ReadOnlyCollection: retainAll disallowed");
118: }
119:
120: public boolean removeAll(Collection c) {
121: throw new UnsupportedOperationException(
122: "ReadOnlyCollection: removeAll disallowed");
123: }
124:
125: public void clear() {
126: throw new UnsupportedOperationException(
127: "ReadOnlyCollection: clear disallowed");
128: }
129: }
|