|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdanbikel.lisp.Sexp
danbikel.lisp.SexpList
public class SexpList
Stores a list of Sexp
objects, which are either symbols
or themselves lists.
Nested Class Summary | |
---|---|
static class |
SexpList.HashCache
A subclass of SexpList where a precomputed, cached
hash value is stored with every instance. |
Field Summary | |
---|---|
static SexpList |
emptyList
An immutable object to represent the empty list. |
Constructor Summary | |
---|---|
SexpList()
Constructs a SexpList with the default initial capacity. |
|
SexpList(int initialCapacity)
Constructs a SexpList with the specified initial capacity. |
|
SexpList(List initialElements)
Constructs a SexpList whose initial elements are those
of initialElements . |
|
SexpList(SexpList initialElements)
Constructs a SexpList whose initial elements are those
of initialElements . |
Method Summary | |
---|---|
SexpList |
add(int index,
Sexp sexp)
Adds sexp at position index , shifting all
elements to the right by one position to make room (an O(n) operation). |
SexpList |
add(Sexp sexp)
Appends sexp to the end of this list. |
boolean |
addAll(int index,
SexpList elementsToAdd)
Adds all the elements in elementsToAdd to this list
at the specified index. |
boolean |
addAll(SexpList elementsToAdd)
Appends all the elements in elementsToAdd to the end of this
list. |
void |
clear()
Removes all elements from this list. |
boolean |
contains(Sexp toFind)
Returns whether the specified S-expression is an element of this list. |
Sexp |
deepCopy()
Returns a deep copy of this list, which means that a full copy of the tree of S-expressions held by this list is returned. |
void |
ensureCapacity(int minCapacity)
Increases the number of elements that this list can hold, if necessary, to be at least minCapacity . |
boolean |
equals(Object o)
Returns true if the specified object is not null
and is an instance of SexpList where the underlying lists
are of the same size and contain Sexp objects that are
equal. |
Sexp |
first()
Returns the first element of this list (identical to calling get(0) ). |
Sexp |
get(int index)
Gets the Sexp at the specified index. |
static SexpList |
getCanonical(SexpList list)
A simple canonicalization method that returns the unique object representing the empty list if the specified list contains no elements. |
Symbol |
getChildLabel(int index)
This convenience method gets the symbol that is the first element of the list that is the element at index . |
int |
hashCode()
Returns the hash code value for this list. |
int |
indexOf(Sexp toFind)
Finds the index of the specified S-expresion. |
boolean |
isAllSymbols()
Returns true if and only if all the elements of this list are
Symbol objects. |
boolean |
isList()
Returns true , because this class and any of its subclasses
represent lists. |
boolean |
isSymbol()
Returns false , because this class and any of its subclasses
represent lists, not symbols. |
Iterator |
iterator()
Returns a read-only iterator for the elements of this list. |
Sexp |
last()
Returns the last element of this list (identical to calling get(size() - 1) ). |
int |
length()
Returns the number of elements in this list. |
SexpList |
listAt(int index)
Returns the list at the specified index. |
void |
readExternal(ObjectInput in)
Reads this object from an ObjectInput instance. |
Sexp |
remove(int index)
Removes the element at index . |
SexpList |
reverse()
Performs an in-place reversal of the elements in this list. |
Sexp |
set(int index,
Sexp element)
Replaces the element at index with element . |
void |
setChildLabel(int index,
Symbol newLabel)
This convenience method replaces the first element of the list that is the element at index to be the symbol newLabel . |
int |
size()
Returns the number of elements in this list. |
Symbol |
symbolAt(int index)
Returns the symbol at the specified index. |
String |
toString()
Returns a string representation of this S-expression, consisting of an open parenthesis, a space-separated string representation of the elements of this list and a close parenthesis. |
void |
trimToSize()
Causes the capacity of this list to be its size. |
void |
trimToSizeRecursive()
Invokes trimToSize not only on this list, but recursively
invokes this method on all elements of this list, thereby trimming
every list in the implicit tree of this list. |
void |
writeExternal(ObjectOutput out)
Writes this object to an ObjectOutput instance. |
Methods inherited from class danbikel.lisp.Sexp |
---|
getCanonical, list, main, read, read, read, symbol |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final SexpList emptyList
Constructor Detail |
---|
public SexpList()
SexpList
with the default initial capacity.
public SexpList(int initialCapacity)
SexpList
with the specified initial capacity.
initialCapacity
- the initial capacity of this listpublic SexpList(SexpList initialElements)
SexpList
whose initial elements are those
of initialElements
. The initial capacity of this
newly-constructed list will be exactly that of the specified list.
Note that the elements of initialElements
are not cloned.
initialElements
- a list of the initial elements of this new listpublic SexpList(List initialElements)
SexpList
whose initial elements are those
of initialElements
. Note that the elements of
initialElements
are not cloned. It is the responsibility
of the caller that initialElements
only contain objects
of type Sexp
.
initialElements
- a list of the initial elements of this new listMethod Detail |
---|
public static final SexpList getCanonical(SexpList list)
list
- the list to be canonicalized, if it is the empty list
public final boolean isList()
true
, because this class and any of its subclasses
represent lists.
isList
in class Sexp
true
public final boolean isSymbol()
false
, because this class and any of its subclasses
represent lists, not symbols.
isSymbol
in class Sexp
false
public SexpList add(Sexp sexp)
sexp
to the end of this list.
sexp
- the S-expression to append
SexpList
objectpublic SexpList add(int index, Sexp sexp)
sexp
at position index
, shifting all
elements to the right by one position to make room (an O(n) operation).
index
- the index at which to add the specified S-expressionsexp
- the S-expression to add
SexpList
objectpublic boolean addAll(SexpList elementsToAdd)
elementsToAdd
to the end of this
list.
elementsToAdd
- the elements to be added at the end of this list
public boolean addAll(int index, SexpList elementsToAdd)
elementsToAdd
to this list
at the specified index.
index
- the index at which to add all the elements of
elementsToAdd
elementsToAdd
- the elements to add at index
public Sexp get(int index)
Sexp
at the specified index.
index
- the index of the list element to be retrieved
Sexp
at the specified index.public Sexp set(int index, Sexp element)
index
with element
.
index
- the index of this list to be set with the specified
Sexp
element
- the element to be set at the specified index of this list
public Sexp remove(int index)
index
.
index
- the index at which to remove an element from this list
IndexOutOfBoundsException
- if the index is out of range
((index < 0 || index >= size())
)public void clear()
public void ensureCapacity(int minCapacity)
minCapacity
.
minCapacity
- the minimum size of the storage capacity of this list
after invocation of this methodpublic void trimToSize()
SexpList
objects.
public void trimToSizeRecursive()
trimToSize
not only on this list, but recursively
invokes this method on all elements of this list, thereby trimming
every list in the implicit tree of this list. This method will never
return if this list represents a cyclic graph rather than a tree.
public int length()
public int size()
public Sexp first()
get(0)
).
public Sexp last()
get(size() - 1)
).
public int indexOf(Sexp toFind)
toFind
- the S-expression to find in this list
toFind
in this list, or -1 if
it does not appear in this listpublic boolean contains(Sexp toFind)
toFind
- the S-expression to find in this list
public SexpList reverse()
SexpList
object, having been reversedpublic Symbol symbolAt(int index)
get(index).symbol()
index
- the index of the symbol to retrieve
index
ClassCastException
- if the element at index
is
not of type Symbol
public SexpList listAt(int index)
get(index).list()
index
- the index of the symbol to retrieve
index
ClassCastException
- if the element at index
is
not of type SexpList
public Symbol getChildLabel(int index)
index
. Invoking
this method is equivalent to the following: get(index).list().get(0).symbol();This method is useful for when
Sexp
s are used to represent labeled trees, where the first
element of a list represents a node label and subsequent elements
represent the children of the node with that label.
index
- the index of the element whose first symbol this method
retrieves
ClassCastException
- if the element at index
is not
a list or if the first element of the list at index
is not
of type Symbol
IndexOutOfBoundsException
- if this list has no element at the
specified index, or if the list that is the element at index
has no elementspublic void setChildLabel(int index, Symbol newLabel)
index
to be the symbol newLabel
.
Invoking this method is equivalent to the following: get(index).list().set(0, newLabel);This method is useful for when
Sexp
s are used to represent labeled trees, where the first
element of a list represents a node label and subsequent elements
represent the children of the node with that label.
index
- the index of the element whose first element is to be replacednewLabel
- the label to be set as the first element of the list
at the specified index
ClassCastException
- if the element at index
is not
a list
IndexOutOfBoundsException
- if this list has no element at the
specified index, or if the list that is the element at index
has no elementspublic final Sexp deepCopy()
deepCopy
in class Sexp
public boolean isAllSymbols()
true
if and only if all the elements of this list are
Symbol
objects.
true
if and only if all the elements of this list are
Symbol
objects.public boolean equals(Object o)
true
if the specified object is not null
and is an instance of SexpList
where the underlying lists
are of the same size and contain Sexp
objects that are
equal. List equality is determined via the implementation of the
equals
method in AbstractList
. Note that two
SexpList
objects may be print-equal but not equal via
this method, which checks for symbol equality (a StringSymbol
and an IntSymbol
may have the same string representation
but can never be the same symbol).
equals
in class Object
o
- the object to test for equality with this list
AbstractList.equals(java.lang.Object)
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public Iterator iterator()
public void writeExternal(ObjectOutput out) throws IOException
ObjectOutput
instance.
writeExternal
in interface Externalizable
writeExternal
in class Sexp
out
- the object stream to which to write an object of this class
IOException
- if the underlying write operation throws an
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
ObjectInput
instance.
readExternal
in interface Externalizable
readExternal
in class Sexp
in
- the object stream from which to read objects of this class
IOException
- if the underlying read operation throws an
IOException
ClassNotFoundException
- if the underlying read operation throws
an ClassNotFoundException
|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |