KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > usermodel > TableIterator


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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
21 import java.util.ArrayList JavaDoc;
22
23 public class TableIterator
24 {
25   Range _range;
26   int _index;
27   int _levelNum;
28
29   TableIterator(Range range, int levelNum)
30   {
31     _range = range;
32     _index = 0;
33     _levelNum = levelNum;
34   }
35
36   public TableIterator(Range range)
37   {
38     this(range, 1);
39   }
40
41
42   public boolean hasNext()
43   {
44     int numParagraphs = _range.numParagraphs();
45     for (;_index < numParagraphs; _index++)
46     {
47       Paragraph paragraph = _range.getParagraph(_index);
48       if (paragraph.isInTable() && paragraph.getTableLevel() == _levelNum)
49       {
50         return true;
51       }
52     }
53     return false;
54   }
55
56   public Table next()
57   {
58     int numParagraphs = _range.numParagraphs();
59     int numRows = 0;
60     int startIndex = _index;
61     int endIndex = _index;
62
63     for (;_index < numParagraphs; _index++)
64     {
65       Paragraph paragraph = _range.getParagraph(_index);
66       if (!paragraph.isInTable() || paragraph.getTableLevel() < _levelNum)
67       {
68         endIndex = _index;
69         break;
70       }
71     }
72     return new Table(startIndex, endIndex, _range, _levelNum);
73   }
74
75 }
76
Popular Tags