KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > UnmodifiableIntCollection


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2002 Søren Bak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package bak.pcj;
20
21 import bak.pcj.util.Exceptions;
22
23 /**
24  * This class represents unmodifiable collections of int values.
25  *
26  * @see java.util.Collections#unmodifiableCollection(java.util.Collection)
27  *
28  * @author Søren Bak
29  * @version 1.1 21-08-2003 20:18
30  * @since 1.0
31  */

32 public class UnmodifiableIntCollection implements IntCollection {
33
34     /** The collection underlying this unmodifiable collection. */
35     protected IntCollection collection;
36
37     /**
38      * Creates a new unmodifiable collection on an existing
39      * collection. The result is a collection whose elements and
40      * behaviour is the same as the existing collection's except
41      * that the new collection cannot be modified.
42      *
43      * @param c
44      * the existing collection to make unmodifiable.
45      *
46      * @throws NullPointerException
47      * if <tt>c</tt> is <tt>null</tt>.
48      */

49     public UnmodifiableIntCollection(IntCollection c) {
50         if (c == null)
51             Exceptions.nullArgument("collection");
52         this.collection = c;
53     }
54
55     /**
56      * Throws <tt>UnsupportedOperationException</tt>.
57      *
58      * @throws UnsupportedOperationException
59      * unconditionally.
60      */

61     public boolean add(int v)
62     { Exceptions.unsupported("add"); throw new RuntimeException JavaDoc(); }
63
64     /**
65      * Throws <tt>UnsupportedOperationException</tt>.
66      *
67      * @throws UnsupportedOperationException
68      * unconditionally.
69      */

70     public boolean addAll(IntCollection c)
71     { Exceptions.unsupported("addAll"); throw new RuntimeException JavaDoc(); }
72
73     /**
74      * Throws <tt>UnsupportedOperationException</tt>.
75      *
76      * @throws UnsupportedOperationException
77      * unconditionally.
78      */

79     public void clear()
80     { Exceptions.unsupported("clear"); }
81
82     public boolean contains(int v)
83     { return collection.contains(v); }
84
85     public boolean containsAll(IntCollection c)
86     { return collection.containsAll(c); }
87
88     public boolean equals(Object JavaDoc obj)
89     { return collection.equals(obj); }
90
91     public int hashCode()
92     { return collection.hashCode(); }
93
94     public boolean isEmpty()
95     { return collection.isEmpty(); }
96
97     public IntIterator iterator() {
98         final IntIterator i = collection.iterator();
99         return new IntIterator() {
100             public boolean hasNext()
101             { return i.hasNext(); }
102
103             public int next()
104             { return i.next(); }
105
106             // It is necessary to override remove() since we have
107
// no way of knowing how iterators are implemented
108
// in the underlying class.
109
public void remove()
110             { Exceptions.unsupported("remove"); }
111         };
112     }
113
114     /**
115      * Throws <tt>UnsupportedOperationException</tt>.
116      *
117      * @throws UnsupportedOperationException
118      * unconditionally.
119      */

120     public boolean remove(int v)
121     { Exceptions.unsupported("remove"); throw new RuntimeException JavaDoc(); }
122
123     /**
124      * Throws <tt>UnsupportedOperationException</tt>.
125      *
126      * @throws UnsupportedOperationException
127      * unconditionally.
128      */

129     public boolean removeAll(IntCollection c)
130     { Exceptions.unsupported("removeAll"); throw new RuntimeException JavaDoc(); }
131
132     /**
133      * Throws <tt>UnsupportedOperationException</tt>.
134      *
135      * @throws UnsupportedOperationException
136      * unconditionally.
137      */

138     public boolean retainAll(IntCollection c)
139     { Exceptions.unsupported("retainAll"); throw new RuntimeException JavaDoc(); }
140
141     public int size()
142     { return collection.size(); }
143
144     public int[] toArray()
145     { return collection.toArray(); }
146
147     public int[] toArray(int[] a)
148     { return collection.toArray(a); }
149
150     public void trimToSize()
151     { }
152
153 }
Popular Tags