KickJava   Java API By Example, From Geeks To Geeks.

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


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.FloatIterator;
22 import bak.pcj.util.Exceptions;
23 import java.util.Iterator JavaDoc;
24
25 /**
26  * This class represents adaptions of primitive iterators over
27  * float values to Java Collections Framework iterators.
28  *
29  * @author Søren Bak
30  * @version 1.2 21-08-2003 19:00
31  * @since 1.0
32  */

33 public class FloatIteratorToIteratorAdapter implements Iterator {
34
35     /** The underlying iterator. */
36     private FloatIterator iterator;
37
38     /**
39      * Creates a new adaption to an iterator from an iterator
40      * over float values.
41      *
42      * @param iterator
43      * the underlying iterator.
44      *
45      * @throws NullPointerException
46      * if <tt>iterator</tt> is <tt>null</tt>.
47      */

48     public FloatIteratorToIteratorAdapter(FloatIterator iterator) {
49         if (iterator == null)
50             Exceptions.nullArgument("iterator");
51         this.iterator = iterator;
52     }
53
54     /**
55      * Indicates whether more values can be returned by this
56      * iterator.
57      *
58      * @return <tt>true</tt> if more values can be returned
59      * by this iterator; returns <tt>false</tt>
60      * otherwise.
61      *
62      * @see #next()
63      */

64     public boolean hasNext()
65     { return iterator.hasNext(); }
66
67     /**
68      * Returns the next value of this iterator.
69      *
70      * @return the next value of this iterator.
71      *
72      * @throws NoSuchElementException
73      * if no more elements are available from this
74      * iterator.
75      *
76      * @see #hasNext()
77      */

78     public Object JavaDoc next()
79     { return new Float JavaDoc(iterator.next()); }
80
81     /**
82      * Removes the last value returned from the underlying
83      * collection.
84      *
85      * @throws UnsupportedOperationException
86      * if removal is not supported by this iterator.
87      *
88      * @throws IllegalStateException
89      * if no element has been returned by this iterator
90      * yet.
91      */

92     public void remove()
93     { iterator.remove(); }
94
95 }
Popular Tags