01: /*
02: * Primitive Collections for Java.
03: * Copyright (C) 2002, 2003 Søren Bak
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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.ShortIterator;
22: import bak.pcj.util.Exceptions;
23: import java.util.Iterator;
24:
25: /**
26: * This class represents adaptions of primitive iterators over
27: * short 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 ShortIteratorToIteratorAdapter implements Iterator {
34:
35: /** The underlying iterator. */
36: private ShortIterator iterator;
37:
38: /**
39: * Creates a new adaption to an iterator from an iterator
40: * over short 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 ShortIteratorToIteratorAdapter(ShortIterator 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: /**
69: * Returns the next value of this iterator.
70: *
71: * @return the next value of this iterator.
72: *
73: * @throws NoSuchElementException
74: * if no more elements are available from this
75: * iterator.
76: *
77: * @see #hasNext()
78: */
79: public Object next() {
80: return new Short(iterator.next());
81: }
82:
83: /**
84: * Removes the last value returned from the underlying
85: * collection.
86: *
87: * @throws UnsupportedOperationException
88: * if removal is not supported by this iterator.
89: *
90: * @throws IllegalStateException
91: * if no element has been returned by this iterator
92: * yet.
93: */
94: public void remove() {
95: iterator.remove();
96: }
97:
98: }
|