01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hwpf.usermodel;
19:
20: import java.util.ArrayList;
21:
22: public class TableIterator {
23: Range _range;
24: int _index;
25: int _levelNum;
26:
27: TableIterator(Range range, int levelNum) {
28: _range = range;
29: _index = 0;
30: _levelNum = levelNum;
31: }
32:
33: public TableIterator(Range range) {
34: this (range, 1);
35: }
36:
37: public boolean hasNext() {
38: int numParagraphs = _range.numParagraphs();
39: for (; _index < numParagraphs; _index++) {
40: Paragraph paragraph = _range.getParagraph(_index);
41: if (paragraph.isInTable()
42: && paragraph.getTableLevel() == _levelNum) {
43: return true;
44: }
45: }
46: return false;
47: }
48:
49: public Table next() {
50: int numParagraphs = _range.numParagraphs();
51: int numRows = 0;
52: int startIndex = _index;
53: int endIndex = _index;
54:
55: for (; _index < numParagraphs; _index++) {
56: Paragraph paragraph = _range.getParagraph(_index);
57: if (!paragraph.isInTable()
58: || paragraph.getTableLevel() < _levelNum) {
59: endIndex = _index;
60: break;
61: }
62: }
63: return new Table(startIndex, endIndex, _range, _levelNum);
64: }
65:
66: }
|