KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > adapter > FloatListIteratorToListIteratorAdapter


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2002, 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.adapter;
20
21 import bak.pcj.list.FloatListIterator;
22 import bak.pcj.util.Exceptions;
23 import java.util.ListIterator JavaDoc;
24
25 /**
26  * This class represents adaptions of primitive list iterators over
27  * float values to Java Collections Framework list iterators.
28  *
29  * @author Søren Bak
30  * @version 1.2 21-08-2003 18:59
31  * @since 1.0
32  */

33 public class FloatListIteratorToListIteratorAdapter implements ListIterator {
34
35     /** The underlying primitive iterator. */
36     protected FloatListIterator iterator;
37
38     /**
39      * Creates a new adaption of a primitive list iterator over
40      * float values to a Java Collections Framework list iterator.
41      *
42      * @param iterator
43      * the primitive iterator to adapt.
44      *
45      * @throws NullPointerException
46      * if <tt>iterator</tt> is <tt>null</tt>.
47      */

48     public FloatListIteratorToListIteratorAdapter(FloatListIterator iterator) {
49         if (iterator == null)
50             Exceptions.nullArgument("iterator");
51         this.iterator = iterator;
52     }
53
54     /**
55      * Adds a specified element to the list at this iterator's
56      * current position.
57      *
58      * @param o
59      * the element to add.
60      *
61      * @throws UnsupportedOperationException
62      * if addition is not supported by this
63      * iterator.
64      *
65      * @throws ClassCastException
66      * if <tt>o</tt> is not of class
67      * {@link Float Float}.
68      *
69      * @throws NullPointerException
70      * if <tt>o</tt> is <tt>null</tt>.
71      */

72     public void add(Object JavaDoc o)
73     { iterator.add( ((Float JavaDoc)o).floatValue() ); }
74
75     /**
76      * Indicates whether more values can be returned by this
77      * iterator.
78      *
79      * @return <tt>true</tt> if more values can be returned
80      * by this iterator; returns <tt>false</tt>
81      * otherwise.
82      *
83      * @see #next()
84      */

85     public boolean hasNext()
86     { return iterator.hasNext(); }
87
88     /**
89      * Indicates whether more values can be returned by this
90      * iterator by calling <tt>previous()</tt>.
91      *
92      * @return <tt>true</tt> if more values can be returned
93      * by this iterator in backwards direction; returns
94      * <tt>false</tt> otherwise.
95      *
96      * @see #previous()
97      */

98     public boolean hasPrevious()
99     { return iterator.hasPrevious(); }
100
101     /**
102      * Returns the next value of this iterator.
103      *
104      * @return the next value of this iterator.
105      *
106      * @throws NoSuchElementException
107      * if no more elements are available from this
108      * iterator.
109      *
110      * @see #hasNext()
111      */

112     public Object JavaDoc next()
113     { return new Float JavaDoc(iterator.next()); }
114
115     /**
116      * Returns the index of the element that would be returned by
117      * a call to <tt>next()</tt>.
118      *
119      * @return the index of the element that would be returned by
120      * a call to <tt>next()</tt>.
121      *
122      * @see #next()
123      */

124     public int nextIndex()
125     { return iterator.nextIndex(); }
126
127     /**
128      * Returns the previous value of this iterator.
129      *
130      * @return the previous value of this iterator.
131      *
132      * @throws NoSuchElementException
133      * if no more elements are available from this
134      * iterator in backwards direction.
135      *
136      * @see #hasPrevious()
137      */

138     public Object JavaDoc previous()
139     { return new Float JavaDoc(iterator.previous()); }
140
141     /**
142      * Returns the index of the element that would be returned by
143      * a call to <tt>previous()</tt>.
144      *
145      * @return the index of the element that would be returned by
146      * a call to <tt>previous()</tt>; if no more elements
147      * are available in backwards direction, <tt>-1</tt>
148      * is returned.
149      *
150      * @see #previous()
151      */

152     public int previousIndex()
153     { return iterator.previousIndex(); }
154
155     /**
156      * Removes the last value returned from the underlying
157      * collection.
158      *
159      * @throws UnsupportedOperationException
160      * if removal is not supported by this iterator.
161      *
162      * @throws IllegalStateException
163      * if no element has been returned by this iterator
164      * yet.
165      */

166     public void remove()
167     { iterator.remove(); }
168
169     /**
170      * Sets the last element returned to a specified value.
171      *
172      * @param o
173      * the new value of the element.
174      *
175      * @throws UnsupportedOperationException
176      * if replacement is not supported by this iterator.
177      *
178      * @throws IllegalStateException
179      * if no element has been returned by this iterator
180      * yet.
181      *
182      * @throws ClassCastException
183      * if <tt>o</tt> is not of class
184      * {@link Float Float}.
185      *
186      * @throws NullPointerException
187      * if <tt>o</tt> is <tt>null</tt>.
188      */

189     public void set(Object JavaDoc o)
190     { iterator.set(((Float JavaDoc)o).floatValue()); }
191
192 }
Popular Tags