|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectgeneralHelpers.TreeNode
generalHelpers.ListNode<T>
public class ListNode<T extends TreeNode>
Base class for lists of AST elements.
(See TreeNode for a discussion of AST nodes in general)
List phyla have a distinct set of operations for constructing and accessing
lists. For each phylum named X there is a phylum called ListNode
An empty list is created with new ListNode
. Elements
may be appended to the list using either addElement()
or
appendElement()
. appendElement
returns the
list itself, so calls to it may be chained, as in
list.appendElement(Foo).appendElement(Bar).appendElement(Baz)
.
ListNode implements the interface Iterable to iterate through lists. If you are not familiar with that interface, look it up in the Java API documentation. Here's an example of iterating through a list:
for (Class_ c : classes) { ... do something with c ... }If you need to have an integer index:
int i = -1; for (Class_ c : classes) { i++; ... do something with c and i... }To loop through two lists of equal length in parallel:
Iteratori1, i2; Class_ c1, c2; i1 = myListNode1.iterator(); i2 = myListNode2.iterator(); for(; i1.hasNext(); ) { c1 = i1.next(); c2 = i2.next(); ... do something with c1 and c2... }
Field Summary |
---|
Fields inherited from class generalHelpers.TreeNode |
---|
lineNumber |
Constructor Summary | |
---|---|
ListNode(int lineNumber)
Builds a new list node |
Method Summary | |
---|---|
ListNode<T> |
appendElement(T element)
Appends an element to the list. |
ListNode<T> |
copy()
no type-safety provided by the copy-method |
java.util.Vector<T> |
copyElements()
Creates a deep copy of this list. |
void |
dump(java.io.Writer out,
int n)
Pretty-prints this list to this output stream. |
int |
getLength()
Retreives the length of the list. |
java.util.Iterator<T> |
iterator()
Returns an iterator for easy data-access. |
java.lang.String |
toString()
Returns a string representation of this list. |
Methods inherited from class generalHelpers.TreeNode |
---|
copyAbstractSymbol, copyBoolean, dumpAbstractSymbol, dumpBoolean, dumpLine, getLineNumber, set |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ListNode(int lineNumber)
lineNumber
- line in the source file from which this node came.Method Detail |
---|
public java.util.Vector<T> copyElements()
public int getLength()
public ListNode<T> appendElement(T element)
The appendElement() method returns the list modified list of the appropriate
type, so that it can be used like this:
l.appendElement(i).appendElement(j).appendElement(k);
element
- a node to appendpublic ListNode<T> copy()
copy
in class TreeNode
public void dump(java.io.Writer out, int n) throws java.io.IOException
dump
in class TreeNode
out
- the output streamn
- the number of spaces to indent the output
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T extends TreeNode>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |