View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Util: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
4   //
5   // This file is part of MillScript-Util.
6   //
7   // MillScript-Util is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-Util is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-Util; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.office.spreadsheet.rows;
22  
23  import org.millscript.commons.util.iterator.AbstractListIterator;
24  import org.millscript.office.spreadsheet.Cell;
25  import org.millscript.office.spreadsheet.Row;
26  
27  /**
28   * This class provides a list interator implementation which iterates over a
29   * slice of a shared object array.
30   */
31  public class SharedRowListIterator extends AbstractListIterator< Row > {
32  
33      /**
34       * The index of the first row in the iteration.
35       */
36      private final int firstIndex;
37  
38      /**
39       * The number of rows in the iteration.
40       */
41      private final int size;
42  
43      /**
44       * The backing data store for this worksheet, a two dimensional array,
45       * an array of array of cells. A null entry indicates the row is empty.
46       */
47      private Cell[][] rowData;
48  
49      /**
50       * Constructs a new shared array list iterator to iterate over a slice of
51       * the specified object array.
52       *
53       * @param objects   the object array whose slice to iterate over
54       * @param start the index(one based, inclusive) to start iterating from
55       * @param end   the index(one based, inclusive) to stop iterating at
56       */
57      public SharedRowListIterator( final Cell[][] objects, final int start, final int end ) {
58          this.firstIndex = start - 1;
59          this.size = end - start + 1;
60          this.rowData = objects;
61      }
62  
63      /**
64       * @see org.millscript.commons.util.iterator.AbstractMapIterator#getValue()
65       */
66      @Override
67      protected Row getValue() {
68          final Cell[] row = this.rowData[ this.firstIndex + super.position - 1 ];
69          if ( row == null ) {
70              return new RowImpl();
71          } else {
72              return new RowImpl( row, true );
73          }
74      }
75  
76      /**
77       * @see org.millscript.commons.util.MapIterator#hasNext()
78       */
79      public boolean hasNext() {
80          return super.position < this.size;
81      }
82  
83      /**
84       * @see org.millscript.commons.util.iterator.AbstractMapIterator#outOfBounds()
85       */
86      @Override
87      protected boolean outOfBounds() {
88          return super.position == 0 || super.position > this.size;
89      }
90  
91  }