View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel 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-Excel 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-Excel; 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.worksheets;
22  
23  import org.millscript.commons.util.ListIterator;
24  import org.millscript.commons.util.Listlet;
25  import org.millscript.commons.util.maplet.IListlet;
26  import org.millscript.office.spreadsheet.Row;
27  import org.millscript.office.spreadsheet.RowRef;
28  import org.millscript.office.spreadsheet.WorksheetRef;
29  import org.millscript.office.spreadsheet.rows.RowRefImpl;
30  
31  /**
32   * 
33   */
34  public class WorksheetRefListIterator implements ListIterator< RowRef > {
35  
36      private final WorksheetRef worksheetRef;
37  
38      private final ListIterator< Row > rowIterator;
39  
40      private int rowOffset;
41  
42      /**
43       * 
44       */
45      public WorksheetRefListIterator( final WorksheetRef bookRef, final int offset, final ListIterator< Row > iterator ) {
46          this.worksheetRef = bookRef;
47          this.rowIterator = iterator;
48          this.rowOffset = offset;
49      }
50  
51      public Integer currentKey() {
52          return this.rowIterator.currentKey();
53      }
54  
55      public Listlet< RowRef > currentMaplet() {
56          return new IListlet< RowRef >(
57              this.rowIterator.currentKey(),
58              this.currentValue()
59          );
60      }
61  
62      public RowRef currentValue() {
63          return new RowRefImpl(
64              this.worksheetRef,
65              this.rowOffset + this.rowIterator.currentKey().intValue(),
66              this.rowIterator.currentValue(),
67              0
68          );
69      }
70  
71      public boolean hasNext() {
72          return this.rowIterator.hasNext();
73      }
74  
75      public Integer nextKey() {
76          return this.rowIterator.nextKey();
77      }
78  
79      public Listlet< RowRef > nextMaplet() {
80          return new IListlet< RowRef >(
81              this.rowIterator.nextKey(),
82              this.currentValue()
83          );
84      }
85  
86      public RowRef nextValue() {
87          return new RowRefImpl(
88              this.worksheetRef,
89              this.rowIterator.nextKey().intValue(),
90              this.rowIterator.currentValue(),
91              0
92          );
93      }
94  
95  }