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.rows;
22  
23  import org.millscript.commons.alert.alerts.Unimplemented;
24  import org.millscript.commons.util.IList;
25  import org.millscript.commons.util.ListIterator;
26  import org.millscript.commons.util.list.AbstractIList;
27  import org.millscript.office.spreadsheet.Cell;
28  import org.millscript.office.spreadsheet.CellRef;
29  import org.millscript.office.spreadsheet.Row;
30  import org.millscript.office.spreadsheet.RowRef;
31  import org.millscript.office.spreadsheet.WorksheetRef;
32  
33  /**
34   * 
35   */
36  public class RowRefImpl extends AbstractIList< CellRef > implements RowRef {
37  
38      private IList< Cell > cellList;
39  
40      private int cellOffset;
41  
42      private int rowIndex;
43  
44      private WorksheetRef worksheetRef;
45  
46      public RowRefImpl( final WorksheetRef sheetRef, final int index, final IList< Cell > cells, final int offset ) {
47          this.cellList = cells;
48          this.cellOffset = offset;
49          this.rowIndex = index;
50          this.worksheetRef = sheetRef;
51      }
52  
53      /**
54       * @see org.millscript.commons.util.list.AbstractIList#doGet(int)
55       */
56      @Override
57      protected CellRef doGet( final int pos ) {
58          return new RowCellRefImpl(
59              this,
60              this.cellOffset + pos,
61              this.cellList.get( pos )
62          );
63      }
64  
65      /**
66       * @see org.millscript.commons.util.list.AbstractIList#doSlice(int, int, boolean)
67       */
68      @Override
69      protected IList< CellRef > doSlice( final int first, final int last, final boolean share ) {
70          return new RowRefImpl(
71              this.worksheetRef,
72              this.rowIndex,
73              this.cellList.slice( first, last, share ),
74              this.cellOffset + first - 1
75          );
76      }
77  
78      /**
79       * @see org.millscript.office.spreadsheet.RowRef#getRow()
80       */
81      public Row getRow() {
82          return this.worksheetRef.getWorksheet().get( rowIndex );
83      }
84  
85      /**
86       * @see org.millscript.office.spreadsheet.RowRef#getRowIndex()
87       */
88      public int getRowIndex() {
89          return this.rowIndex;
90      }
91  
92      /**
93       * @see org.millscript.office.spreadsheet.RowRef#getWorksheetRef()
94       */
95      public WorksheetRef getWorksheetRef() {
96          return this.worksheetRef;
97      }
98  
99      /**
100      * @see org.millscript.commons.util.IList#indexOf(V)
101      */
102     public int indexOf( final CellRef value ) {
103         // TODO Auto-generated method stub
104         throw new Unimplemented(
105             "A indexOf operation was required"
106         ).culprit( "class", this.getClass() );
107     }
108 
109     /**
110      * @see org.millscript.commons.util.IList#iterator(boolean)
111      */
112     public ListIterator< CellRef > iterator( final boolean share ) {
113         return new RowRefListIterator(
114             this,
115             this.cellList.iterator( share )
116         );
117     }
118 
119     /**
120      * @see org.millscript.commons.util.IMap#size()
121      */
122     public int size() {
123         return this.cellList.size();
124     }
125 
126 }