KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jag > template > TemplateTextBlockList


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */

17
18 package com.finalist.jag.template;
19
20
21 import java.util.*;
22
23
24 /**
25  * Class TemplateTextBlockCollection
26  *
27  *
28  * @author Wendel D. de Witte
29  * @version %I%, %G%
30  */

31 public class TemplateTextBlockList extends LinkedList {
32
33    /**
34     * Method setCollection
35     *
36     *
37     *
38     */

39    public TemplateTextBlockList() {
40    }
41
42
43    /**
44     * Method add
45     *
46     *
47     * @param block
48     *
49     */

50    public void add(TemplateTextBlock block) {
51       this.addLast(block);
52    }
53
54
55    /**
56     * Method add
57     *
58     *
59     *
60     * @param block1
61     * @param block2
62     *
63     *
64     * @return
65     */

66    public TemplateTextBlockList cut(TemplateTextBlock block1,
67       TemplateTextBlock block2) {
68
69       TemplateTextBlockList list = new TemplateTextBlockList();
70       int nIndex1 = indexOf(block1);
71       int nIndex2 = indexOf(block2);
72
73       while ((nIndex1 != -1) && (nIndex1 <= nIndex2)) {
74          list.add(list.get(nIndex1));
75          remove(nIndex1++);
76       }
77
78       return list;
79    }
80
81
82    /**
83     * Method getBefore
84     *
85     *
86     * @param block
87     *
88     * @return
89     *
90     */

91    public TemplateTextBlock getBefore(TemplateTextBlock block) {
92
93       int nIndex = indexOf(block);
94
95       if (nIndex == -1) {
96          return null;
97       }
98
99       ListIterator iterator = listIterator(nIndex);
100
101       return iterator.hasPrevious()
102          ? (TemplateTextBlock) iterator.previous()
103          : null;
104    }
105
106
107    /**
108     * Method getAfter
109     *
110     *
111     * @param block
112     *
113     * @return
114     *
115     */

116    public TemplateTextBlock getAfter(TemplateTextBlock block) {
117
118       int nIndex = indexOf(block);
119
120       if (nIndex == -1) {
121          return null;
122       }
123
124       ListIterator iterator = listIterator(nIndex);
125
126       return iterator.hasNext()
127          ? (TemplateTextBlock) iterator.next()
128          : null;
129    }
130
131
132    /**
133     * Method getStringBuffer
134     *
135     *
136     * @return
137     *
138     */

139    public StringBuffer JavaDoc getStringBuffer() {
140
141       StringBuffer JavaDoc returnValue = new StringBuffer JavaDoc();
142       ListIterator iterator = listIterator();
143
144       while (iterator.hasNext()) {
145          returnValue
146             .append(((TemplateTextBlock) iterator.next()).getText());
147       }
148
149       return returnValue;
150    }
151
152
153    /**
154     * Method toArray
155     *
156     *
157     * @return
158     *
159     */

160    public TemplateTextBlock[] toTextBlockArray() {
161       return (TemplateTextBlock[]) super
162          .toArray(new TemplateTextBlock[size()]);
163    }
164 }
Popular Tags