xtc.parser
Class Sequence

java.lang.Object
  extended by xtc.tree.Node
      extended by xtc.parser.Element
          extended by xtc.parser.Sequence
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, Locatable

public class Sequence
extends Element

A sequence of grammar elements.

A sequence may have an optional name. However, this name is not considered when comparing sequences for equality.

Version:
$Revision: 1.30 $
Author:
Robert Grimm

Nested Class Summary
 
Nested classes/interfaces inherited from class xtc.parser.Element
Element.Tag
 
Field Summary
 java.util.List<Element> elements
          The ordered list of grammar elements.
 SequenceName name
          The optional name.
 
Constructor Summary
Sequence()
          Create a new, empty sequence.
Sequence(Element element)
          Create a new sequence with the specified element.
Sequence(int capacity)
          Create a new, empty sequence with the specified capacity.
Sequence(java.util.List<Element> elements)
          Create a new sequence.
Sequence(SequenceName name, java.util.List<Element> elements)
          Create a new sequence.
 
Method Summary
 Sequence add(Element e)
          Add the specified element to this sequence.
 Sequence addAll(java.util.List<Element> l)
          Add all elements in the specified list to this sequence.
 Sequence clear()
          Remove all elements from this sequence.
static Sequence ensure(Element e)
          Ensure that the specified element is a sequence.
 boolean equals(java.lang.Object o)
           
 Element get(int idx)
          Get the element at the specified index.
 int hashCode()
           
 boolean hasTrailingChoice()
          Determine whether this sequence's last element is an ordered choice.
 boolean isEmpty()
          Determine whether this sequence is empty.
 int size()
          Get the size of this sequence.
 Sequence subSequence(int start)
          Create a new subsequence from the specified start index.
 Sequence subSequence(int start, int end)
          Create a new subsequence for the specified indices.
 Element.Tag tag()
          Get this element's tag.
 void write(java.lang.Appendable out)
          Write a human readable representation to the specified appendable.
 
Methods inherited from class xtc.tree.Node
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, getBoolean, getBooleanProperty, getGeneric, getList, getLocation, getName, getNode, getProperty, getString, getStringProperty, getTokenText, hasLocation, hasName, hasProperty, hasTraversal, hasVariable, indexOf, isAnnotation, isGeneric, isList, isToken, iterator, lastIndexOf, properties, remove, removeProperty, set, setLocation, setLocation, setProperty, strip, toAnnotation, toList, toString, toToken
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public SequenceName name
The optional name.


elements

public java.util.List<Element> elements
The ordered list of grammar elements.

Constructor Detail

Sequence

public Sequence()
Create a new, empty sequence.


Sequence

public Sequence(int capacity)
Create a new, empty sequence with the specified capacity.

Parameters:
capacity - The capacity.

Sequence

public Sequence(java.util.List<Element> elements)
Create a new sequence.

Parameters:
elements - The list of elements.

Sequence

public Sequence(SequenceName name,
                java.util.List<Element> elements)
Create a new sequence.

Parameters:
name - The name.
elements - The list of elements.

Sequence

public Sequence(Element element)
Create a new sequence with the specified element. If the element is another sequence, the new sequence has the same elements but is a copy. Otherwise, the new sequence has the specified element as its only element. In either case, the new sequence has the element's location.

Parameters:
element - The element.
Method Detail

tag

public Element.Tag tag()
Description copied from class: Element
Get this element's tag.

Specified by:
tag in class Element
Returns:
The tag.

clear

public Sequence clear()
Remove all elements from this sequence.

Returns:
This sequence.

add

public Sequence add(Element e)
Add the specified element to this sequence.

Parameters:
e - The element to add.
Returns:
This sequence.

addAll

public Sequence addAll(java.util.List<Element> l)
Add all elements in the specified list to this sequence.

Parameters:
l - The list of elements.
Returns:
This sequence.

isEmpty

public boolean isEmpty()
Determine whether this sequence is empty.

Overrides:
isEmpty in class Node
Returns:
true if this is an empty sequence.

size

public int size()
Get the size of this sequence.

Overrides:
size in class Node
Returns:
The size.

get

public Element get(int idx)
Get the element at the specified index.

Overrides:
get in class Node
Parameters:
idx - The index.
Returns:
The element at that position.
Throws:
java.lang.IndexOutOfBoundsException - Signals that the index is out of range.
See Also:
Token.test(Object), Token.cast(Object), GNode.test(Object), GNode.cast(Object)

hasTrailingChoice

public boolean hasTrailingChoice()
Determine whether this sequence's last element is an ordered choice.

Returns:
true if the last element is a choice.

subSequence

public Sequence subSequence(int start)
Create a new subsequence from the specified start index. The new subsequence ends with the last element of this sequence.

Parameters:
start - The inclusive start index.
Returns:
The subsequence.
Throws:
java.lang.IndexOutOfBoundsException - Signals that the index is out of range.

subSequence

public Sequence subSequence(int start,
                            int end)
Create a new subsequence for the specified indices.

Parameters:
start - The inclusive start index.
end - The exclusive end index.
Returns:
The subsequence.
Throws:
java.lang.IndexOutOfBoundsException - Signals that the index is out of range.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

write

public void write(java.lang.Appendable out)
           throws java.io.IOException
Description copied from class: Node
Write a human readable representation to the specified appendable. If this node supports generic traversal, the default implementation writes this node in algebraic term-format; otherwise, it writes the string returned by Object.toString().

Overrides:
write in class Node
Parameters:
out - The appendable.
Throws:
java.io.IOException - Signals an I/O error.

ensure

public static Sequence ensure(Element e)
Ensure that the specified element is a sequence. If the specified element is not a sequence, a new sequence with the specified element as its only element is returned; the newly created sequence has the element's location.

Parameters:
e - The element.
Returns:
The element in/as a sequence.


Copyright © 2012. All Rights Reserved.