/** * Version 1.0 is to handle single variable 2DSquareCelled raster data. * Copyright (C) 2005 Andy Turner, CCG, University of Leeds, UK. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ package uk.ac.leeds.ccg.andyt.grids.core; import java.util.Iterator; import java.util.NoSuchElementException; import uk.ac.leeds.ccg.andyt.grids.utilities.AbstractIterator; /** * For iterating through the values in a Grid2DSquareCellDouble instance. The * values are not returned in any particular order. */ public class Grid2DSquareCellDoubleIterator extends AbstractIterator { private Iterator _Grid2DSquareCellDoubleHashMapIterator; private AbstractGrid2DSquareCellDoubleChunk _Grid2DSquareCellDoubleChunk; private AbstractIterator _Grid2DSquareCellDoubleChunkIterator; /** Creates a new instance of Grid2DSquareDoubleIterator */ public Grid2DSquareCellDoubleIterator() {} /** * Creates a new instance of Grid2DSquareDoubleIterator * @param grid2DSquareCellDouble The Grid2DSquareCellDouble to iterate over. */ public Grid2DSquareCellDoubleIterator( Grid2DSquareCellDouble grid2DSquareCellDouble ) { this._Grid2DSquareCellDoubleHashMapIterator = grid2DSquareCellDouble._ChunkID_AbstractGrid2DSquareCellChunk_HashMap.values().iterator(); if ( _Grid2DSquareCellDoubleHashMapIterator.hasNext() ) { //this.grid2DSquareCellDoubleChunkIterator = // ( ( AbstractGrid2DSquareCellDoubleChunk ) // this.grid2DSquareCellDoubleHashMapIterator.next() ); this._Grid2DSquareCellDoubleChunk = ( AbstractGrid2DSquareCellDoubleChunk ) this._Grid2DSquareCellDoubleHashMapIterator.next(); initGrid2DSquareCellDoubleChunkIterator(); } } /** * Initialises this.grid2DSquareCellDoubleChunkIterator from * this.grid2DSquareCellDoubleChunk */ private void initGrid2DSquareCellDoubleChunkIterator() { try { this._Grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunk64CellMapIterator( ( Grid2DSquareCellDoubleChunk64CellMap ) this._Grid2DSquareCellDoubleChunk ); } catch ( ClassCastException cce0 ) { try { this._Grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunkArrayIterator( ( Grid2DSquareCellDoubleChunkArray ) this._Grid2DSquareCellDoubleChunk ); } catch ( ClassCastException cce1 ) { try { this._Grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunkJAIIterator( ( Grid2DSquareCellDoubleChunkJAI ) this._Grid2DSquareCellDoubleChunk ); } catch ( ClassCastException cce2 ) { this._Grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunkMapIterator( ( Grid2DSquareCellDoubleChunkMap ) this._Grid2DSquareCellDoubleChunk ); } } } } /** * Initialises this.grid2DSquareCellDoubleChunkIterator from * this.grid2DSquareCellDoubleChunk */ public AbstractIterator initGrid2DSquareCellDoubleChunkIterator( AbstractGrid2DSquareCellDoubleChunk grid2DSquareCellDoubleChunk ) { AbstractIterator grid2DSquareCellDoubleChunkIterator; try { grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunk64CellMapIterator( ( Grid2DSquareCellDoubleChunk64CellMap ) grid2DSquareCellDoubleChunk ); } catch ( ClassCastException cce0 ) { try { grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunkArrayIterator( ( Grid2DSquareCellDoubleChunkArray ) grid2DSquareCellDoubleChunk ); } catch ( ClassCastException cce1 ) { try { grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunkJAIIterator( ( Grid2DSquareCellDoubleChunkJAI ) grid2DSquareCellDoubleChunk ); } catch ( ClassCastException cce2 ) { grid2DSquareCellDoubleChunkIterator = new Grid2DSquareCellDoubleChunkMapIterator( ( Grid2DSquareCellDoubleChunkMap ) grid2DSquareCellDoubleChunk ); } } } return grid2DSquareCellDoubleChunkIterator; } /** * Returns true if the iteration has more elements. (In other * words, returns true if next would return an element * rather than throwing an exception.) * * @return true if the iterator has more elements. */ @Override public boolean hasNext() { if ( this._Grid2DSquareCellDoubleChunkIterator.hasNext() ) { return true; } else { while ( _Grid2DSquareCellDoubleHashMapIterator.hasNext() ) { //this.grid2DSquareCellDoubleChunkIterator = // ( ( AbstractGrid2DSquareCellDoubleChunk ) // this.grid2DSquareCellDoubleHashMapIterator.next() ); AbstractGrid2DSquareCellDoubleChunk grid2DSquareCellDoubleChunk = ( AbstractGrid2DSquareCellDoubleChunk ) this._Grid2DSquareCellDoubleHashMapIterator.next(); AbstractIterator grid2DSquareCellDoubleChunkIterator = initGrid2DSquareCellDoubleChunkIterator( grid2DSquareCellDoubleChunk ); if ( grid2DSquareCellDoubleChunkIterator.hasNext() ) { return true; } } } return false; } /** * Returns the next element in the iteration. * * @return the next element in the iteration. * @exception NoSuchElementException iteration has no more elements. */ @Override public Object next() { if ( this._Grid2DSquareCellDoubleChunkIterator.hasNext() ) { return this._Grid2DSquareCellDoubleChunkIterator.next(); } else { while ( _Grid2DSquareCellDoubleHashMapIterator.hasNext() ) { //this.grid2DSquareCellDoubleChunkIterator = // ( ( AbstractGrid2DSquareCellDoubleChunk ) // this.grid2DSquareCellDoubleHashMapIterator.next() ); this._Grid2DSquareCellDoubleChunk = ( AbstractGrid2DSquareCellDoubleChunk ) this._Grid2DSquareCellDoubleHashMapIterator.next(); this._Grid2DSquareCellDoubleChunkIterator = initGrid2DSquareCellDoubleChunkIterator( _Grid2DSquareCellDoubleChunk ); if ( this._Grid2DSquareCellDoubleChunkIterator.hasNext() ) { return this._Grid2DSquareCellDoubleChunkIterator.next(); } } } // Should this be an error? or null or what return new NoSuchElementException(); //return null; } /** * * Removes from the underlying collection the last element returned by the * iterator (optional operation). This method can be called only once per * call to next. The behavior of an iterator is unspecified if * the underlying collection is modified while the iteration is in * progress in any way other than by calling this method. * * @exception UnsupportedOperationException if the remove * operation is not supported by this Iterator. * * @exception IllegalStateException if the next method has not * yet been called, or the remove method has already * been called after the last call to the next * method. */ @Override public void remove() {} }