|
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
danbikel.parser.SexpSubcatEvent
public class SexpSubcatEvent
Represents an event composed of zero or more Sexp
objects
and zero or one Subcat
object.
Bugs: The fact that no more than one Subcat
object can be added to this event type does not follow the general
contract of Event
, which specifies that when an
Event
advertises that it can collect elements of a
certain type, it should contain some sort of a list of such objects
internally, to be accessed via the Event.get(int,int)
method. However, since Subcat
objects are not simplex
entities but are themselves collections, this (current) limitation
is not entirely unreasonable.
Field Summary | |
---|---|
static Symbol |
sexpSubcatLabel
Initial symbol used in the string representation of SexpSubcatEvent objects. |
protected Subcat |
subcat
The subcat data member. |
Fields inherited from class danbikel.parser.SexpEvent |
---|
event, sexpLabel |
Constructor Summary | |
---|---|
SexpSubcatEvent()
Constructs an event containing no components. |
|
SexpSubcatEvent(int initialCapacity)
Creates a new object capable of efficiently collecting the specified number of components of the type Sexp . |
Method Summary | |
---|---|
MutableEvent |
add(int type,
Object obj)
Adds the specified type of object to this event. |
MutableEvent |
add(Object obj)
Adds the specified component to this event. |
int |
canonicalize(Map canonical)
Canonicalizes the backing Sexp and Subcat
components of this event using the specified reflexive map. |
void |
clear()
Clears the data stored in this complex event object. |
Event |
copy()
Returns a deep copy of this event, using SexpEvent.copy to
copy the backing Sexp , and using Event.copy
to copy the backing Subcat , if there is one. |
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)
Gets the index th component of this event of
the specified type. |
Class |
getClass(int type)
Gets the class object associated with the specified type index. |
int |
hashCode()
Returns the hash code of this event, based on its components. |
int |
numComponents()
Returns the number of components of this event: the number of Sexp objects plus the number of Subcat objects. |
int |
numComponents(int type)
Returns the number of Sexp components or the number of
Subcat components that are part of this event. |
int |
numTypes()
Returns 2, as this Event implementation supports only two
types. |
void |
readExternal(ObjectInput in)
Reconstructs the SexpEvent object that was serialized using
SexpEvent.writeExternal(ObjectOutput) . |
Sexp |
toSexp()
If this event has no subcat, then this method simply returns the backing Sexp ; otherwise, this method returns a SexpList
of the form (sexp subcat) , where sexp
is the Sexp component(s) of this event and subcat
is the result of calling subcat.toSexp() . |
String |
toString()
Returns a string representation of this object of the form ( sexpSubcatLabel event)
where event is string representation of the Sexp
held by this object. |
int |
typeIndex(Class cl)
Gets the type index associated with the specified class. |
void |
writeExternal(ObjectOutput out)
Writes a representation of this object to the specified object output stream. |
Methods inherited from class danbikel.parser.SexpEvent |
---|
copySexpEvent, ensureCapacity, ensureCapacity, setSexp |
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 sexpSubcatLabel
SexpSubcatEvent
objects.
toString()
protected Subcat subcat
Constructor Detail |
---|
public SexpSubcatEvent()
public SexpSubcatEvent(int initialCapacity)
Sexp
. The initial
capacity does not apply to components of type Subcat
, as
this Event
implementation does not support more than
1 Subcat
component.
initialCapacity
- the pre-allocated capacity for objects of type
Sexp
for this eventMethod Detail |
---|
public Class getClass(int type)
Event
implementation are
Sexp
and Subcat
.
getClass
in interface Event
getClass
in class SexpEvent
Class
) associated with the specified
type indexpublic int typeIndex(Class cl)
Event
implementation are
Sexp
and Subcat
, so this method
is guaranteed to return either 0 or 1 for these classes, or -1 if the
specified class is neither of these two classes.
typeIndex
in interface Event
typeIndex
in class SexpEvent
public int numTypes()
Event
implementation supports only two
types.
numTypes
in interface Event
numTypes
in class SexpEvent
public int numComponents()
Sexp
objects plus the number of Subcat
objects.
The number of Sexp
objects is 1 if the backing
Sexp
is a symbol, or the length of the list otherwise.
Due to limitations of the implementation of this event type, there can be
at most 1 Subcat
object.
numComponents
in interface Event
numComponents
in class SexpEvent
public int numComponents(int type)
Sexp
components or the number of
Subcat
components that are part of this event.
Due to limitations of the implementation of this event type, there can be
at most 1 Subcat
object.
numComponents
in interface Event
numComponents
in class SexpEvent
public Object get(int type, int index)
index
th component of this event of
the specified type. If the type is that for Sexp
and
the backing Sexp
is a symbol, then the specified index must
be 0; otherwise, the index must be within the range of the backing
SexpList
. If the type is that for Subcat
,
then the specified index must be 0, as this Event
implementation only supports the storage of at most 1 Subcat
object.
get
in interface Event
get
in class SexpEvent
type
- the type index of the component to getindex
- the index of the component to get
IndexOutOfBoundsException
- if
type
< 0 or if
type >= numTypes()
or if
index < 0
or if
index >= numComponents(type)
typeIndex(Class)
public MutableEvent add(Object obj)
N.B.: Given that this implementation only supports at most
1 Subcat
component, if the specified object is of type
Subcat
and this event already has such a
component, then the existing subcat will be (silently!) replaced
by the specified subcat. Put another way, it is an error to add
more than one Subcat
object to a
SexpSubcatEvent
object.
add
in interface MutableEvent
add
in class SexpEvent
obj
- the component to add to this event
SexpEvent
objectpublic MutableEvent add(int type, Object obj)
typeIndex(Subcat.class)
, then the specified object
must be an instance of Subcat
and is added as this event's subcat.
If the specified object type is typeIndex(Sexp.class)
, then
the object must be of type Sexp
and is added to this event's list
of Sexp
elements.
add
in interface MutableEvent
add
in class SexpEvent
type
- the type of object to be added to this eventobj
- the object to be added to this event
SexpSubcatEvent
objecttypeIndex(Class)
public int canonicalize(Map canonical)
Sexp
and Subcat
components of this event using the specified reflexive map.
canonicalize
in interface Event
canonicalize
in class SexpEvent
canonical
- a reflexive map used for canonicalization
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 Event copy()
SexpEvent.copy
to
copy the backing Sexp
, and using Event.copy
to copy the backing Subcat
, if there is one.
Bugs: The subcat is not deeply copied, as we are using "caller-copy" semantics, that is, that any thread that wishes to use a modified version of a subcat must take care to copy an existing subcat before making the modification. This convention is potentially dangerous, but is in place for efficiency.
copy
in interface Event
copy
in class SexpEvent
SexpEvent.copy()
,
Event.copy()
public int hashCode()
hashCode
in interface Event
hashCode
in class SexpEvent
public boolean equals(Object o)
SexpEvent
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 Event
equals
in class SexpEvent
public String toString()
sexpSubcatLabel
event)
where event is string representation of the Sexp
held by this object.
toString
in class SexpEvent
public Sexp toSexp()
Sexp
; otherwise, this method returns a SexpList
of the form (sexp subcat)
, where sexp
is the Sexp
component(s) of this event and subcat
is the result of calling subcat.toSexp()
.
toSexp
in interface SexpConvertible
toSexp
in class SexpEvent
SexpConvertible
,
Subcat.toSexp()
public void clear()
SexpEvent
clear
in interface MutableEvent
clear
in class SexpEvent
public void writeExternal(ObjectOutput out) throws IOException
SexpEvent
writeExternal
in interface Externalizable
writeExternal
in class SexpEvent
out
- the stream to which to write a representation of this object
IOException
- if there is a problem writing to the specified
output streampublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
SexpEvent
SexpEvent
object that was serialized using
SexpEvent.writeExternal(ObjectOutput)
.
readExternal
in interface Externalizable
readExternal
in class SexpEvent
in
- 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 |