001: /*
002: * Primitive Collections for Java.
003: * Copyright (C) 2002, 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.adapter;
020:
021: import bak.pcj.list.FloatListIterator;
022: import bak.pcj.util.Exceptions;
023: import java.util.ListIterator;
024:
025: /**
026: * This class represents adaptions of Java Collections Framework
027: * list iterators to primitive list iterators over float values.
028: *
029: * <p>
030: * Adapters from JCF collections to primitive collections will
031: * fail if the JCF collection contains <tt>null</tt> values or
032: * values of the wrong class. However, adapters are not fast
033: * failing in the case that the underlying collection should
034: * contain illegal values. To implement fast failure would require
035: * every operation to check every element of the underlying
036: * collection before doing anything. Instead validation methods
037: * are provided. They can be called using the assertion facility
038: * in the client code:
039: * <pre>
040: * CollectionToFloatCollectionAdapter s;
041: * ...
042: * <b>assert</b> s.validate();
043: * </pre>
044: * or by letting the adapter throw an exception on illegal values:
045: * <pre>
046: * CollectionToFloatCollectionAdapter s;
047: * ...
048: * s.evalidate(); // Throws an exception on illegal values
049: * </pre>
050: * Either way, validation must be invoked directly by the client
051: * code.
052: *
053: * @author Søren Bak
054: * @version 1.2 20-08-2003 23:17
055: * @since 1.0
056: */
057: public class ListIteratorToFloatListIteratorAdapter implements
058: FloatListIterator {
059:
060: /** The underlying iterator. */
061: protected ListIterator iterator;
062:
063: /**
064: * Creates a new adaption of a list iterator to a primitive
065: * list iterator over float values.
066: *
067: * @param iterator
068: * the iterator to adapt to a primitive iterator.
069: *
070: * @throws NullPointerException
071: * if <tt>iterator</tt> is <tt>null</tt>.
072: */
073: public ListIteratorToFloatListIteratorAdapter(ListIterator iterator) {
074: if (iterator == null)
075: Exceptions.nullArgument("iterator");
076: this .iterator = iterator;
077: }
078:
079: public void add(float v) {
080: iterator.add(new Float(v));
081: }
082:
083: public boolean hasNext() {
084: return iterator.hasNext();
085: }
086:
087: public boolean hasPrevious() {
088: return iterator.hasPrevious();
089: }
090:
091: public float next() {
092: return ((Float) iterator.next()).floatValue();
093: }
094:
095: public int nextIndex() {
096: return iterator.nextIndex();
097: }
098:
099: public float previous() {
100: return ((Float) iterator.previous()).floatValue();
101: }
102:
103: public int previousIndex() {
104: return iterator.previousIndex();
105: }
106:
107: public void remove() {
108: iterator.remove();
109: }
110:
111: public void set(float v) {
112: iterator.set(new Float(v));
113: }
114:
115: }
|