|
Parsing Engine | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdanbikel.parser.AbstractEvent
danbikel.parser.SexpEvent
public class SexpEvent
Represents an event composed of one or more Sexp
objects. For efficiency reasons, this class treats as equal a
backing Sexp that is a symbol and a backing
Sexp that is a list whose sole element is the same
symbol. As per the guidelines of MutableEvent, this
class implements the ensureCapacity methods, so that a
single SexpEvent object may be re-used for efficiency.
| Field Summary | |
|---|---|
protected Sexp |
event
The event stored by this instance. |
static Symbol |
sexpLabel
Initial symbol used in the string representation of SexpEvent
objects. |
| Constructor Summary | |
|---|---|
SexpEvent()
Constructs a SexpEvent that contains no data. |
|
SexpEvent(int initialCapacity)
Constructs a SexpEvent that contains no data, but
whose ensureCapacity(int) method has been called with
the specified value. |
|
SexpEvent(Sexp event)
Creates a new SexpEvent using the specified S-expression. |
|
| Method Summary | |
|---|---|
MutableEvent |
add(int type,
Object obj)
Identical to add(obj). |
MutableEvent |
add(Object obj)
Adds the specified object, which must be a Sexp instance,
to this event. |
int |
canonicalize(Map canonical)
Since events are typically read-only, this method will allow for canonicalization (or "unique-ifying") of the information contained in this event. |
void |
clear()
Clears the data stored in this complex event object. |
Event |
copy()
Returns a deep copy of this event, which really just means creating a new instance with a deep copy of the backing Sexp, using the Sexp.deepCopy method. |
protected Sexp |
copySexpEvent()
Returns a deep copy of the underlying Sexp of this event. |
void |
ensureCapacity(int size)
If size is greater than 1, this method
ensures that the underlying Sexp is a
SexpList (creating a new SexpList if
necessary) and pre-allocates space in that SexpList. |
void |
ensureCapacity(int type,
int size)
Since there is only one type supported by this class, this method simply calls ensureCapacity(size). |
boolean |
equals(Object o)
Returns true if o is an instance of Event and if the backing Sexp of o is equal to the backing Sexp of this object; also, this method treats backing Sexp of the two objects equal
when one is a symbol and the other is a list of length 1
containing that symbol. |
Object |
get(int type,
int index)
Returns the indexth component of this event. |
Class |
getClass(int type)
Returns Sexp.class if the specified type is 0. |
int |
hashCode()
Returns the hash code of the backing Sexp object. |
int |
numComponents()
Returns the number of components of this event: 1 if the backing Sexp is a symbol, or the length of the list otherwise. |
int |
numComponents(int type)
An alias for numComponents(), as this Event
implementation supports only one type. |
int |
numTypes()
Returns 1, as this Event implementation supports only one
type. |
void |
readExternal(ObjectInput in)
Reconstructs the SexpEvent object that was serialized using
writeExternal(ObjectOutput). |
void |
setSexp(Sexp event)
Sets the backing Sexp of this object to be the specified Sexp. |
Sexp |
toSexp()
Returns the Sexp contained in this event. |
String |
toString()
Returns a string representation of this object of the form ( sexpLabel event)
where event is string representation of the Sexp
held by this object. |
int |
typeIndex(Class cl)
Returns 0 if the specified class is Sexp.class, -1
otherwise. |
void |
writeExternal(ObjectOutput out)
Writes a representation of this object to the specified object output stream. |
| Methods inherited from class danbikel.parser.AbstractEvent |
|---|
genericEquals |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Symbol sexpLabel
SexpEvent
objects.
toString()protected Sexp event
| Constructor Detail |
|---|
public SexpEvent()
SexpEvent that contains no data.
public SexpEvent(int initialCapacity)
SexpEvent that contains no data, but
whose ensureCapacity(int) method has been called with
the specified value.
public SexpEvent(Sexp event)
SexpEvent using the specified S-expression.
event - the Sexp representing an arbitrary event.| Method Detail |
|---|
public Class getClass(int type)
Sexp.class if the specified type is 0.
getClass in interface EventClass) associated with the specified
type index
IndexOutOfBoundsException - if the specified type is not 0public int typeIndex(Class cl)
Sexp.class, -1
otherwise.
typeIndex in interface Eventpublic int numTypes()
Event implementation supports only one
type.
numTypes in interface Eventpublic int numComponents()
Sexp is a symbol, or the length of the list otherwise.
numComponents in interface Eventpublic int numComponents(int type)
numComponents(), as this Event
implementation supports only one type.
numComponents in interface Event
public Object get(int type,
int index)
indexth component of this event.
If the backing Sexp is a symbol, then index
must be 0; otherwise, it must be not be outside the acceptable index range
of the backing SexpList.
get in interface Eventtype - the type index of the component to be retrieved (which must
be zero, since SexpEvent objects only have one possible type)index - the index of the component to be retrieved
IndexOutOfBoundsException - if
type != 0 or if
index < 0 or if
index >= numComponents(type)public Event copy()
Sexp, using the Sexp.deepCopy method. As a
special exception, if the underlying Sexp of this
event is a list with only one element that is a symbol, the copy
will contain a Sexp that is that symbol (the
"canonical" version of lists containing a single symbol, as
far as this class is concerned). This transforms a time-efficient
lookup object using a pre-allocated underlying list into a
space-efficient object suitable for persistent storage.
copy in interface EventcopySexpEvent(),
equals(Object),
ensureCapacity(int)protected final Sexp copySexpEvent()
Sexp of this event.
If the underlying Sexp is a single-element list containing
a symbol, the symbol is returned instead of a copy of the list.
public int hashCode()
Sexp object.
As a special case, if the backing Sexp is a list with a
single symbol, the hash code returned is that of the single symbol.
This behavior is consistent with this class' semantics of treating
a symbol and a list containing that symbol as equivalent.
hashCode in interface EventhashCode in class Objectpublic boolean equals(Object o)
Sexp of the two objects equal
when one is a symbol and the other is a list of length 1
containing that symbol.
As per the general contract of Event.equals(Object), the
specified object need not be of type SexpEvent, but merely
support the same types as this Event, namely Sexp
objects, and store the same number of equal Sexp objects in
the same order.
equals in interface Eventequals in class Objectpublic String toString()
sexpLabel event)
where event is string representation of the Sexp
held by this object.
toString in class Objectpublic void setSexp(Sexp event)
public Sexp toSexp()
Sexp contained in this event.
toSexp in interface SexpConvertiblepublic MutableEvent add(Object obj)
Sexp instance,
to this event.
add in interface MutableEventobj - a Sexp instance to add to this event
SexpEvent object
public MutableEvent add(int type,
Object obj)
add(obj).
add in interface MutableEventtype - an ignored parameterobj - an event to add to this complex event object
SexpEvent objectadd(Object)public int canonicalize(Map canonical)
canonicalize in interface Eventcanonical - a reflexive map of objecs representing event
information: for each unique key-value pair, the value is a
reference to the key
Sexp was a list and was therefore
canonicalized, 0 if it was a list but was not canonicalized (and had to
be added to canonical) or -1 if this event was a
Symbol and was therefore not even eligible for
canonicalizationpublic void ensureCapacity(int size)
size is greater than 1, this method
ensures that the underlying Sexp is a
SexpList (creating a new SexpList if
necessary) and pre-allocates space in that SexpList.
For efficiency when creating lookup SexpEvent
objects, once the underlying Sexp is a
SexpList, it will remain as such, even if cleared
and only one symbol is added. However, when the
copy method is invoked, if the underlying
Sexp of this SexpEvent object is a list
with a single symbol sym, the returned
SexpEvent object will have a "canonicalized" underlying
Sexp that is sym (that is, the list of a single
symbol will be turned into the symbol itself). This scheme allows
a lookup object using a pre-allocated list for time efficiency to
be transformed into a space-efficient object suitable for persistent
storage.
ensureCapacity in interface MutableEventsize - the amount of space to pre-allocate for the underlying
list of Sexp componentscopy()
public void ensureCapacity(int type,
int size)
ensureCapacity(size).
ensureCapacity in interface MutableEventtype - the type of underlying abstract list for which to pre-allocate
spacesize - the size to pre-allocate for the specified type of abstract
listpublic void clear()
clear in interface MutableEvent
public void writeExternal(ObjectOutput out)
throws IOException
writeExternal in interface Externalizableout - the stream to which to write a representation of this object
IOException - if there is a problem writing to the specified
output stream
public void readExternal(ObjectInput in)
throws IOException,
ClassNotFoundException
SexpEvent object that was serialized using
writeExternal(ObjectOutput).
readExternal in interface Externalizablein - the input stream from which to reconstruct a SexpEvent
object
IOException - if there is a problem reading from the specified
input stream
ClassNotFoundException - if the concrete type of the serialized
object read from the specified input stream cannot be found
|
Parsing Engine | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||