Parsing Engine

danbikel.parser
Interface Event

All Superinterfaces:
Serializable
All Known Subinterfaces:
MutableEvent, Subcat
All Known Implementing Classes:
AbstractEvent, BrokenSubcatBag, SexpEvent, SubcatBag, SubcatList

public interface Event
extends Serializable

Provides the specification for arbitrary event types, to be used when collecting counts for and computing probabilities of arbitrary events. Event objects have to satisfy the rather conflicting design goals of providing an abstraction for events composed of arbitrarily-typed components, efficiency of access, efficiency of storage and notational felicity when composing an event. Therefore, the general contract of Event objects is that they provide the means to store sequences of different types of components, such that two Events are guaranteed to be equal if components of the same type have been added in the same order and are pairwise equal. Put another way, Event objects can be thought of abstractly as a set of lists, with one list for each type of object they are capable of collecting, where two Event objects are equal if all of their corresponding lists are equal. This contract achieves notational convenience when composing an event, because MutableEvent.add(Object) will add the specified object to the appropriate list. For example, if two MutableEvent objects event1 and event2 are composed via the following code

 event1.add(new Integer(2)).add("foo").add(new Integer(3));
 event2.add("foo").add(new Integer(2)).add(new Integer(3));
 
it is guaranteed that event1.equals(event2) will return true.

Event objects must explicitly publish the run-time types of objects they are capable of collecting, and these types may include Object, as well as primitive types. This publishing is accomplished via the method getClass(int), which maps integers in the range [0,numTypes()) to Class objects.


Method Summary
 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.
 Event copy()
          Returns a deep copy of this event of the same run-time type.
 boolean equals(Object obj)
          Returns true if and only if the following three conditions are met: the specified object is an instance of Event the specified object supports the same and only the same types of components as this Event object the abstract lists of each type for this object and the specified object are of equal length and are pairwise equal in their items
 Object get(int type, int index)
          Gets the indexth component of the specified type from this event.
 Class getClass(int type)
          Maps the specified integer to a type that this Event is capable of collecting.
 int hashCode()
          Returns the hash code for this event.
 int numComponents()
          Gets the total number of components of this event.
 int numComponents(int type)
          Gets the number of components of this event of a particular type.
 int numTypes()
          Returns the number of component types capable of being collected by this Event implementation.
 int typeIndex(Class cl)
          Returns the integer constant associated with the specified event component type, or -1 if this event does not support the specified class.
 

Method Detail

getClass

public Class getClass(int type)
Maps the specified integer to a type that this Event is capable of collecting. Type indices are required to fill the range [0, numTypes()) for all types supported by an Event implementation.

Returns:
the type (Class) associated with the specified type index

typeIndex

public int typeIndex(Class cl)
Returns the integer constant associated with the specified event component type, or -1 if this event does not support the specified class.


numTypes

public int numTypes()
Returns the number of component types capable of being collected by this Event implementation.


numComponents

public int numComponents()
Gets the total number of components of this event.


numComponents

public int numComponents(int type)
Gets the number of components of this event of a particular type.


get

public Object get(int type,
                  int index)
Gets the indexth component of the specified type from this event. If an implementation of this interface supports primitive type values, then these values should be wrapped in their corresponding wrapper classes. For example, if an implementation collects int values, then these values should be returned by this method wrapped in Integer objects.

Throws:
IndexOutOfBoundsException - if type < 0 or if type >= numTypes() or if index < 0 or if index >= numComponents(type)

copy

public Event copy()
Returns a deep copy of this event of the same run-time type.


canonicalize

public 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. Use of this method is intended to conserve memory by removing duplicate copies of event information in different event objects.

Parameters:
canonical - a reflexive map of objecs representing event information: for each unique key-value pair, the value is a reference to the key
Returns:
1 if this event was canonicalized, 0 if it was not canonicalized (and had to be added to canonical) or -1 if this event was not even eligible for canonicalization

hashCode

public int hashCode()
Returns the hash code for this event.

Returns:
the hash code for this event

equals

public boolean equals(Object obj)
Returns true if and only if the following three conditions are met:

Parsing Engine

Author: Dan Bikel.