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.worksheets;
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.alerts.InvalidIndexForListsAlert;
27 import org.millscript.commons.util.list.AbstractIList;
28 import org.millscript.office.spreadsheet.ColumnRef;
29 import org.millscript.office.spreadsheet.Row;
30 import org.millscript.office.spreadsheet.RowRef;
31 import org.millscript.office.spreadsheet.WorkbookRef;
32 import org.millscript.office.spreadsheet.Worksheet;
33 import org.millscript.office.spreadsheet.WorksheetRef;
34 import org.millscript.office.spreadsheet.rows.RowRefImpl;
35
36 /**
37 *
38 */
39 public class WorksheetRefImpl extends AbstractIList< RowRef > implements WorksheetRef {
40
41 private IList< Row > rowList;
42
43 private int rowOffset;
44
45 private WorkbookRef workbookRef;
46
47 private Worksheet worksheet;
48
49 public WorksheetRefImpl( final WorkbookRef bookRef, final Worksheet sheet, final IList< Row > rows, final int offset ) {
50 this.rowList = rows;
51 this.rowOffset = offset;
52 this.workbookRef = bookRef;
53 this.worksheet = sheet;
54 }
55
56 /**
57 * @see org.millscript.commons.util.list.AbstractIList#doGet(int)
58 */
59 @Override
60 protected RowRef doGet( final int pos ) {
61 return new RowRefImpl(
62 this,
63 this.rowOffset + pos,
64 this.rowList.get( pos ),
65 0
66 );
67 }
68
69 /**
70 * @see org.millscript.commons.util.list.AbstractIList#doSlice(int, int, boolean)
71 */
72 @Override
73 protected IList< RowRef > doSlice( final int first, final int last, final boolean share ) {
74 return new WorksheetRefImpl(
75 this.workbookRef,
76 this.worksheet,
77 this.rowList.slice( first, last, share ),
78 this.rowOffset + first - 1
79 );
80 }
81
82 /**
83 * @see org.millscript.office.spreadsheet.WorksheetRef#getColumnRef(int)
84 */
85 public ColumnRef getColumnRef( final int pos ) {
86
87 throw new Unimplemented(
88 "A column reference was required"
89 ).culprit( "class", this.getClass() );
90 }
91
92 /**
93 * @see org.millscript.office.spreadsheet.WorksheetRef#getColumnRef(java.lang.Integer)
94 */
95 public ColumnRef getColumnRef( final Integer pos ) {
96 if ( pos == null ) {
97 throw new InvalidIndexForListsAlert().culprit(
98 "key",
99 pos
100 ).decorate( this ).mishap();
101 } else {
102 return this.getColumnRef( pos.intValue() );
103 }
104 }
105
106 /**
107 * @see org.millscript.office.spreadsheet.WorksheetRef#getColumnRef0(int)
108 */
109 public ColumnRef getColumnRef0( final int pos ) {
110 return this.getColumnRef( pos + 1 );
111 }
112
113 /**
114 * @see org.millscript.office.spreadsheet.WorksheetRef#getColumnRef0(java.lang.Integer)
115 */
116 public ColumnRef getColumnRef0( final Integer pos ) {
117 if ( pos == null ) {
118 throw new InvalidIndexForListsAlert().culprit(
119 "key",
120 pos
121 ).decorate( this ).mishap();
122 } else {
123 return this.getColumnRef0( pos.intValue() );
124 }
125 }
126
127 /**
128 * @see org.millscript.office.spreadsheet.WorksheetRef#getColumnRefList()
129 */
130 public IList< ColumnRef > getColumnRefList() {
131
132 throw new Unimplemented(
133 "A column reference list was required"
134 ).culprit( "class", this.getClass() );
135 }
136
137 /**
138 * @see org.millscript.office.spreadsheet.WorksheetRef#getWorkbookRef()
139 */
140 public WorkbookRef getWorkbookRef() {
141 return this.workbookRef;
142 }
143
144 /**
145 * @see org.millscript.office.spreadsheet.WorksheetRef#getWorksheet()
146 */
147 public Worksheet getWorksheet() {
148 return this.worksheet;
149 }
150
151 /**
152 * @see org.millscript.commons.util.IList#indexOf(V)
153 */
154 public int indexOf( final RowRef value ) {
155
156 throw new Unimplemented(
157 "A indexOf a RowRef operation was required"
158 ).culprit( "class", this.getClass() );
159 }
160
161 /**
162 * @see org.millscript.commons.util.IList#iterator(boolean)
163 */
164 public ListIterator< RowRef > iterator( final boolean share ) {
165 return new WorksheetRefListIterator(
166 this,
167 this.rowOffset,
168 this.rowList.iterator( share )
169 );
170 }
171
172 /**
173 * @see org.millscript.commons.util.IMap#size()
174 */
175 public int size() {
176 return this.rowList.size();
177 }
178
179 }