KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > list > UnmodifiableIntList


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2003 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.list;
20
21 import bak.pcj.util.Exceptions;
22
23 import bak.pcj.IntCollection;
24 import bak.pcj.UnmodifiableIntCollection;
25
26 /**
27  * This class represents unmodifiable lists of int values.
28  *
29  * @see java.util.Collections#unmodifiableList(java.util.List)
30  *
31  * @author Søren Bak
32  * @version 1.1 24-08-2003 20:52
33  * @since 1.0
34  */

35 public class UnmodifiableIntList extends UnmodifiableIntCollection implements IntList {
36
37     /**
38      * Creates a new unmodifiable list on an existing
39      * list. The result is a list whose elements and
40      * behaviour is the same as the existing list's except
41      * that the new list cannot be modified.
42      *
43      * @param l
44      * the existing list to make unmodifiable.
45      *
46      * @throws NullPointerException
47      * if <tt>l</tt> is <tt>null</tt>.
48      */

49     public UnmodifiableIntList(IntList l) {
50         super(l);
51     }
52
53     private IntList list()
54     { return (IntList)collection; }
55
56     /**
57      * Throws <tt>UnsupportedOperationException</tt>.
58      *
59      * @throws UnsupportedOperationException
60      * unconditionally.
61      */

62     public void add(int index, int v)
63     { Exceptions.unmodifiable("list"); }
64
65     /**
66      * Throws <tt>UnsupportedOperationException</tt>.
67      *
68      * @throws UnsupportedOperationException
69      * unconditionally.
70      */

71     public boolean addAll(int index, IntCollection c)
72     { Exceptions.unmodifiable("list"); return false; }
73
74     public int get(int index)
75     { return list().get(index); }
76
77     public int indexOf(int c)
78     { return list().indexOf(c); }
79
80     /**
81      * @since 1.2
82      */

83     public int indexOf(int index, int c)
84     { return list().indexOf(index, c); }
85
86     public int lastIndexOf(int c)
87     { return list().lastIndexOf(c); }
88
89     /**
90      * @since 1.2
91      */

92     public int lastIndexOf(int index, int c)
93     { return list().lastIndexOf(index, c); }
94
95     public IntListIterator listIterator()
96     { return listIterator(0); }
97
98     public IntListIterator listIterator(int index) {
99         final IntListIterator i = list().listIterator(index);
100         return new IntListIterator() {
101             public boolean hasNext()
102             { return i.hasNext(); }
103
104             public int next()
105             { return i.next(); }
106
107             // It is necessary to override remove() since we have
108
// no way of knowing how iterators are implemented
109
// in the underlying class.
110
public void remove()
111             { Exceptions.unmodifiable("list"); }
112             
113             public void add(int v)
114             { Exceptions.unmodifiable("list"); }
115
116             public boolean hasPrevious()
117             { return i.hasPrevious(); }
118
119             public int nextIndex()
120             { return i.nextIndex(); }
121
122             public int previous()
123             { return i.previous(); }
124             
125             public int previousIndex()
126             { return i.previousIndex(); }
127
128             public void set(int v)
129             { Exceptions.unmodifiable("list"); }
130         };
131     }
132
133     /**
134      * Throws <tt>UnsupportedOperationException</tt>.
135      *
136      * @throws UnsupportedOperationException
137      * unconditionally.
138      */

139     public int removeElementAt(int index)
140     { Exceptions.unmodifiable("list"); throw new RuntimeException JavaDoc(); }
141
142     /**
143      * Throws <tt>UnsupportedOperationException</tt>.
144      *
145      * @throws UnsupportedOperationException
146      * unconditionally.
147      */

148     public int set(int index, int v)
149     { Exceptions.unmodifiable("list"); throw new RuntimeException JavaDoc(); }
150
151 }
Popular Tags