001: /*
002: * Primitive Collections for Java.
003: * Copyright (C) 2002 Søren Bak
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package bak.pcj;
020:
021: import bak.pcj.util.Exceptions;
022:
023: /**
024: * This class represents unmodifiable collections of short values.
025: *
026: * @see java.util.Collections#unmodifiableCollection(java.util.Collection)
027: *
028: * @author Søren Bak
029: * @version 1.1 21-08-2003 20:18
030: * @since 1.0
031: */
032: public class UnmodifiableShortCollection implements ShortCollection {
033:
034: /** The collection underlying this unmodifiable collection. */
035: protected ShortCollection collection;
036:
037: /**
038: * Creates a new unmodifiable collection on an existing
039: * collection. The result is a collection whose elements and
040: * behaviour is the same as the existing collection's except
041: * that the new collection cannot be modified.
042: *
043: * @param c
044: * the existing collection to make unmodifiable.
045: *
046: * @throws NullPointerException
047: * if <tt>c</tt> is <tt>null</tt>.
048: */
049: public UnmodifiableShortCollection(ShortCollection c) {
050: if (c == null)
051: Exceptions.nullArgument("collection");
052: this .collection = c;
053: }
054:
055: /**
056: * Throws <tt>UnsupportedOperationException</tt>.
057: *
058: * @throws UnsupportedOperationException
059: * unconditionally.
060: */
061: public boolean add(short v) {
062: Exceptions.unsupported("add");
063: throw new RuntimeException();
064: }
065:
066: /**
067: * Throws <tt>UnsupportedOperationException</tt>.
068: *
069: * @throws UnsupportedOperationException
070: * unconditionally.
071: */
072: public boolean addAll(ShortCollection c) {
073: Exceptions.unsupported("addAll");
074: throw new RuntimeException();
075: }
076:
077: /**
078: * Throws <tt>UnsupportedOperationException</tt>.
079: *
080: * @throws UnsupportedOperationException
081: * unconditionally.
082: */
083: public void clear() {
084: Exceptions.unsupported("clear");
085: }
086:
087: public boolean contains(short v) {
088: return collection.contains(v);
089: }
090:
091: public boolean containsAll(ShortCollection c) {
092: return collection.containsAll(c);
093: }
094:
095: public boolean equals(Object obj) {
096: return collection.equals(obj);
097: }
098:
099: public int hashCode() {
100: return collection.hashCode();
101: }
102:
103: public boolean isEmpty() {
104: return collection.isEmpty();
105: }
106:
107: public ShortIterator iterator() {
108: final ShortIterator i = collection.iterator();
109: return new ShortIterator() {
110: public boolean hasNext() {
111: return i.hasNext();
112: }
113:
114: public short next() {
115: return i.next();
116: }
117:
118: // It is necessary to override remove() since we have
119: // no way of knowing how iterators are implemented
120: // in the underlying class.
121: public void remove() {
122: Exceptions.unsupported("remove");
123: }
124: };
125: }
126:
127: /**
128: * Throws <tt>UnsupportedOperationException</tt>.
129: *
130: * @throws UnsupportedOperationException
131: * unconditionally.
132: */
133: public boolean remove(short v) {
134: Exceptions.unsupported("remove");
135: throw new RuntimeException();
136: }
137:
138: /**
139: * Throws <tt>UnsupportedOperationException</tt>.
140: *
141: * @throws UnsupportedOperationException
142: * unconditionally.
143: */
144: public boolean removeAll(ShortCollection c) {
145: Exceptions.unsupported("removeAll");
146: throw new RuntimeException();
147: }
148:
149: /**
150: * Throws <tt>UnsupportedOperationException</tt>.
151: *
152: * @throws UnsupportedOperationException
153: * unconditionally.
154: */
155: public boolean retainAll(ShortCollection c) {
156: Exceptions.unsupported("retainAll");
157: throw new RuntimeException();
158: }
159:
160: public int size() {
161: return collection.size();
162: }
163:
164: public short[] toArray() {
165: return collection.toArray();
166: }
167:
168: public short[] toArray(short[] a) {
169: return collection.toArray(a);
170: }
171:
172: public void trimToSize() {
173: }
174:
175: }
|