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.workbooks;
22  
23  import org.millscript.commons.util.IList;
24  import org.millscript.commons.util.ListIterator;
25  import org.millscript.commons.util.list.AbstractIList;
26  import org.millscript.office.spreadsheet.Workbook;
27  import org.millscript.office.spreadsheet.WorkbookRef;
28  import org.millscript.office.spreadsheet.Worksheet;
29  import org.millscript.office.spreadsheet.WorksheetRef;
30  import org.millscript.office.spreadsheet.worksheets.WorksheetRefImpl;
31  
32  /**
33   * 
34   */
35  public class WorkbookRefImpl extends AbstractIList< WorksheetRef > implements WorkbookRef {
36  
37      private Workbook workbook;
38  
39      private IList< Worksheet > worksheetList;
40  
41      private int worksheetOffset;
42  
43      /**
44       * 
45       */
46      public WorkbookRefImpl( final Workbook book ) {
47          this( book, book, 0 );
48      }
49  
50      /**
51       * 
52       */
53      protected WorkbookRefImpl( final Workbook book, final IList< Worksheet > sheetList, final int offset ) {
54          this.workbook = book;
55          this.worksheetList = sheetList;
56          this.worksheetOffset = offset;
57      }
58  
59      /**
60       * @see org.millscript.commons.util.list.AbstractIList#doGet(int)
61       */
62      @Override
63      protected WorksheetRef doGet( final int pos ) {
64          return new WorksheetRefImpl(
65              this,
66              this.worksheetList.get( this.worksheetOffset + pos ),
67              this.worksheetList.get( this.worksheetOffset + pos ),
68              0
69          );
70      }
71  
72      /**
73       * @see org.millscript.commons.util.list.AbstractIList#doSlice(int, int, boolean)
74       */
75      @Override
76      protected IList< WorksheetRef > doSlice( final int first, final int last, final boolean share ) {
77          return new WorkbookRefImpl(
78              this.workbook,
79              this.worksheetList.slice( first, last, share ),
80              this.worksheetOffset + first - 1
81          );
82      }
83  
84      /**
85       * @see org.millscript.office.spreadsheet.WorkbookRef#getWorkbook()
86       */
87      public Workbook getWorkbook() {
88          return this.workbook;
89      }
90  
91      /**
92       * @see org.millscript.commons.util.IList#indexOf(V)
93       */
94      public int indexOf( final WorksheetRef value ) {
95          if ( value.getWorkbookRef().getWorkbook() == this.workbook ) {
96              final int pos = this.worksheetList.indexOf( value.getWorksheet() );
97              if ( pos > this.worksheetOffset ) {
98                  return pos - this.worksheetOffset;
99              }
100         }
101         return 0;
102     }
103 
104     /**
105      * @see org.millscript.commons.util.IMap#iterator(boolean)
106      */
107     public ListIterator< WorksheetRef > iterator( final boolean share ) {
108         return new WorkbookRefListIterator(
109             this,
110             this.worksheetList.iterator( share )
111         );
112     }
113 
114     /**
115      * @see org.millscript.commons.util.IMap#size()
116      */
117     public int size() {
118         return this.worksheetList.size();
119     }
120 
121 }