-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataLoopNameListNode.java
More file actions
350 lines (330 loc) · 9.95 KB
/
DataLoopNameListNode.java
File metadata and controls
350 lines (330 loc) · 9.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package EDU.bmrb.starlibj;
import java.lang.*;
import java.util.*;
/** This class contains the list of lists of names that represents
* all the tag names for a loop. This class mimics the functionality
* of java.util.vector, so that programmers can learn it easier.
* Each element in this 'vector' is a LoopNameListNode (described
* elsewhere), which is a list of tagnames. Each element in this
* 'vector' is therefore one of the the nesting levels of the loop's
* names. Here is an example. Assume the original star file contained
* the following piece of text:
* <P>
* <PRE>
* loop_
* _tag_I _tag_II _tag_III
* loop_
* _tag_A _tag_B
* loop_
* _tag1 _tag2 _tag3 _tag4
*
* <I>... loop values ... </I>
* </PRE>
* Then the DataLoopNameListNode to store those tag names would
* look like this:
* <TABLE BORDER=YES>
* <TR>
* <TH>index</TH> <TH>contains</TH>
* </TR>
* <TR>
* <TD>0</TD> <TD>a LoopNameListNode which in turn contains
* "_tag_I", "_tag_II", and "_tagIII"</TD>
* </TR>
* <TR>
* <TD>1</TD> <TD>a LoopNameListNode which in turn contains
* "_tag_A" and "_tag_B"</TD>
* </TR>
* <TR>
* <TD>2</TD> <TD>a LoopNameListNode which in turn contains
* "_tag_1", "_tag_2", "_tag3", and "_tag_4"</TD>
* </TR>
* </TABLE>
* @see LoopNameListNode
*/
public class DataLoopNameListNode extends StarNode implements Cloneable
{
/** no-arg constructor */
public DataLoopNameListNode()
{
super();
myRows = new NameListVector();
}
/** copy constructor */
public DataLoopNameListNode( DataLoopNameListNode copyMe )
{
super(copyMe);
int i;
myRows = new NameListVector();
for( i = 0 ; i < copyMe.size() ; i++ )
addElement( (LoopNameListNode) ( copyMe.elementAt(i).clone() ) );
}
/** Copy a vector of LoopNameListNodes */
public DataLoopNameListNode( NameListVector copyMe )
{
super();
int i;
myRows = new NameListVector();
for( i = 0 ; i < copyMe.size() ; i++ )
addElement( (LoopNameListNode)
( ( (LoopNameListNode)
copyMe.elementAt(i)).clone() ) );
}
public Object clone()
{
return new DataLoopNameListNode( this );
}
// -------------------------------------------
// Things designed to mimic Vector:
// -------------------------------------------
/** Just like the Vector method of the same name.
* @see VectorCheckType.setSize
*/
public void setSize(int newSize)
{
myRows.setSize(newSize);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.capacity
*/
public int capacity()
{
return myRows.capacity();
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.size
*/
public int size()
{
return myRows.size();
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.isEmpty
*/
public boolean isEmpty()
{
return myRows.isEmpty();
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.Enumeration
*/
public Enumeration elements()
{
return myRows.elements();
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.contains
*/
public boolean contains(LoopNameListNode row)
{
return myRows.contains(row);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.indexOf
*/
public int indexOf(LoopNameListNode row)
{
return myRows.indexOf(row);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.indexOf
*/
public int indexOf(LoopNameListNode row,
int index)
{
return myRows.indexOf(row,index);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.lastIndexOf
*/
public int lastIndexOf(LoopNameListNode row)
{
return myRows.lastIndexOf( row );
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.lastIndexOf
*/
public int lastIndexOf(LoopNameListNode row,
int index)
{
return myRows.lastIndexOf( row, index );
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.elementAt
*/
public LoopNameListNode elementAt(int index)
{
return (LoopNameListNode) ( myRows.elementAt(index) );
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.firstElement
*/
public LoopNameListNode firstElement()
{
return (LoopNameListNode) ( myRows.firstElement() );
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.lastElement
*/
public LoopNameListNode lastElement()
{
return (LoopNameListNode) ( myRows.lastElement() );
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.setElementAt
*/
public void setElementAt(LoopNameListNode row,
int index)
{
myRows.setElementAt(row,index);
( (LoopNameListNode) (myRows.elementAt(index))
).setParent(this);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.removeElementAt
*/
public void removeElementAt(int index)
{
( (LoopNameListNode) (myRows.elementAt(index))
).setParent(null);
myRows.removeElementAt(index);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.insertElementAt
*/
public void insertElementAt(LoopNameListNode row,
int index)
{
myRows.insertElementAt(row,index);
( (LoopNameListNode) (myRows.elementAt(index))
).setParent(this);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.addElement
*/
public void addElement(LoopNameListNode row)
{
myRows.addElement(row);
( (LoopNameListNode) (myRows.lastElement())
).setParent(this);
}
/** Just like the Vector method of the same name.
* @see VectorCheckType.removeElement
*/
public boolean removeElement( LoopNameListNode row)
{
row.setParent(null);
return myRows.removeElement(row);
}
/** Returns the name of the first tag in the list, which is sometimes
* used to refer to the whole loop list.
* @return null if the list is empty (which should only happen
* when the list is still in creation.)
*/
public String getLabel()
{
if( myRows.size() > 0 )
return ( (LoopNameListNode) myRows.elementAt(0) ).getLabel();
else
return null;
}
/** Find the name given in this name list.
* The search for names is case-insensitive.
*
* @param searchFor look for this tag name, case insensitively.
*/
public VectorCheckType searchByName( String searchFor )
{
VectorCheckType retVal = new VectorCheckType();
VectorCheckType tmpVect;
try
{
retVal.addType( Class.forName( StarValidity.clsNameStarNode ));
retVal.freezeTypes();
int i,j;
for( i = 0 ; i < myRows.size() ; i++ )
{
tmpVect = ( (LoopNameListNode) myRows.elementAt(i)
).searchByName(searchFor);
for( j = 0 ; j < tmpVect.size() ; j++ )
retVal.addElement( tmpVect.elementAt(j));
}
}
catch( ClassNotFoundException exc )
{ System.err.println( "Should never happen exception: " +
exc.getMessage() );
exc.printStackTrace();
return null;
}
return retVal;
}
/** Find the type given in this name list.
* @param searchFor look for this tag name.
*/
public VectorCheckType searchForType( Class type )
{
VectorCheckType retVal = new VectorCheckType();
try
{
retVal.addType( Class.forName( StarValidity.clsNameStarNode ));
retVal.freezeTypes();
if( type.isInstance(this) )
retVal.addElement(this);
}
catch( ClassNotFoundException exc )
{ System.err.println( "Should never happen exception: " +
exc.getMessage() );
exc.printStackTrace();
return null;
}
return retVal;
}
/** Get the index of the given name. Returns the
* nest depth and the column index within that nest depth.
* (indexes start counting at zero, negative numbers returned
* mean the tag was not found.)
* <P>
* Note that the search for tag names is always case-insensitive,
* as per the STAR syntax.
* <P>
* @param tagName The tag to look for.
* @param nestLevel (out) - Returns the nesting level. The use of the
* trivial "RemoteInt" class is required because Java can only
* pass an int by value, and the class "Integer" doesn't have any
* methods for setting the value after construction.
* @param column (out) - Returns the nesting level. The use of the
* trivial "RemoteInt" class is required because Java can only
* pass an int by value, and the class "Integer" doesn't have any
* methods for setting the value after construction.
*/
public void tagPositionDeep( String tagName,
RemoteInt nestLevel, RemoteInt column )
{
boolean foundIt = false;
LoopNameListNode curList;
int i;
for( nestLevel.num = 0; nestLevel.num < myRows.size(); nestLevel.num++ )
{
curList = (LoopNameListNode) myRows.elementAt(nestLevel.num);
column.num = -1;
for( i = 0 ; i < curList.size() ; i++ )
{
if( curList.elementAt(i).getLabel().equalsIgnoreCase( tagName ) )
{
column.num = i;
break;
}
}
if( column.num >= 0 )
{
foundIt = true;
break;
}
}
if( ! foundIt )
{ nestLevel.num = -1;
column.num = -1;
}
return;
}
NameListVector myRows;
}