1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }