001: /*
002: * Primitive Collections for Java.
003: * Copyright (C) 2003 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.list;
020:
021: import bak.pcj.util.Exceptions;
022:
023: import bak.pcj.DoubleCollection;
024: import bak.pcj.UnmodifiableDoubleCollection;
025:
026: /**
027: * This class represents unmodifiable lists of double values.
028: *
029: * @see java.util.Collections#unmodifiableList(java.util.List)
030: *
031: * @author Søren Bak
032: * @version 1.1 24-08-2003 20:52
033: * @since 1.0
034: */
035: public class UnmodifiableDoubleList extends
036: UnmodifiableDoubleCollection implements DoubleList {
037:
038: /**
039: * Creates a new unmodifiable list on an existing
040: * list. The result is a list whose elements and
041: * behaviour is the same as the existing list's except
042: * that the new list cannot be modified.
043: *
044: * @param l
045: * the existing list to make unmodifiable.
046: *
047: * @throws NullPointerException
048: * if <tt>l</tt> is <tt>null</tt>.
049: */
050: public UnmodifiableDoubleList(DoubleList l) {
051: super (l);
052: }
053:
054: private DoubleList list() {
055: return (DoubleList) collection;
056: }
057:
058: /**
059: * Throws <tt>UnsupportedOperationException</tt>.
060: *
061: * @throws UnsupportedOperationException
062: * unconditionally.
063: */
064: public void add(int index, double v) {
065: Exceptions.unmodifiable("list");
066: }
067:
068: /**
069: * Throws <tt>UnsupportedOperationException</tt>.
070: *
071: * @throws UnsupportedOperationException
072: * unconditionally.
073: */
074: public boolean addAll(int index, DoubleCollection c) {
075: Exceptions.unmodifiable("list");
076: return false;
077: }
078:
079: public double get(int index) {
080: return list().get(index);
081: }
082:
083: public int indexOf(double c) {
084: return list().indexOf(c);
085: }
086:
087: /**
088: * @since 1.2
089: */
090: public int indexOf(int index, double c) {
091: return list().indexOf(index, c);
092: }
093:
094: public int lastIndexOf(double c) {
095: return list().lastIndexOf(c);
096: }
097:
098: /**
099: * @since 1.2
100: */
101: public int lastIndexOf(int index, double c) {
102: return list().lastIndexOf(index, c);
103: }
104:
105: public DoubleListIterator listIterator() {
106: return listIterator(0);
107: }
108:
109: public DoubleListIterator listIterator(int index) {
110: final DoubleListIterator i = list().listIterator(index);
111: return new DoubleListIterator() {
112: public boolean hasNext() {
113: return i.hasNext();
114: }
115:
116: public double next() {
117: return i.next();
118: }
119:
120: // It is necessary to override remove() since we have
121: // no way of knowing how iterators are implemented
122: // in the underlying class.
123: public void remove() {
124: Exceptions.unmodifiable("list");
125: }
126:
127: public void add(double v) {
128: Exceptions.unmodifiable("list");
129: }
130:
131: public boolean hasPrevious() {
132: return i.hasPrevious();
133: }
134:
135: public int nextIndex() {
136: return i.nextIndex();
137: }
138:
139: public double previous() {
140: return i.previous();
141: }
142:
143: public int previousIndex() {
144: return i.previousIndex();
145: }
146:
147: public void set(double v) {
148: Exceptions.unmodifiable("list");
149: }
150: };
151: }
152:
153: /**
154: * Throws <tt>UnsupportedOperationException</tt>.
155: *
156: * @throws UnsupportedOperationException
157: * unconditionally.
158: */
159: public double removeElementAt(int index) {
160: Exceptions.unmodifiable("list");
161: throw new RuntimeException();
162: }
163:
164: /**
165: * Throws <tt>UnsupportedOperationException</tt>.
166: *
167: * @throws UnsupportedOperationException
168: * unconditionally.
169: */
170: public double set(int index, double v) {
171: Exceptions.unmodifiable("list");
172: throw new RuntimeException();
173: }
174:
175: }
|