public abstract class AbstractEventReader<P extends ReaderStreamDataProvider<? extends AbstractEventReader<P>>> extends java.lang.Object implements JPhyloIOEventReader, ReadWriteConstants
ATTRIBUTE_STRING_KEY, ATTRIBUTES_NAMESPACE_FOLDER, DATA_TYPE_NAMESPACE_FOLDER, DATA_TYPE_SIMPLE_VALUE_LIST, DEFAULT_CHAR_SET_ID_PREFIX, DEFAULT_CHARACTER_DEFINITION_ID_PREFIX, DEFAULT_EDGE_ID_PREFIX, DEFAULT_GENERAL_ID_PREFIX, DEFAULT_MATRIX_ID_PREFIX, DEFAULT_MAX_COMMENT_LENGTH, DEFAULT_MAX_TOKENS_TO_READ, DEFAULT_META_ID_PREFIX, DEFAULT_NETWORK_ID_PREFIX, DEFAULT_NODE_EDGE_SET_ID_PREFIX, DEFAULT_NODE_ID_PREFIX, DEFAULT_OTU_ID_PREFIX, DEFAULT_OTU_LIST_ID_PREFIX, DEFAULT_OTU_SET_ID_PREFIX, DEFAULT_SEQUENCE_ID_PREFIX, DEFAULT_SEQUENCE_SET_ID_PREFIX, DEFAULT_TOKEN_DEFINITION_ID_PREFIX, DEFAULT_TOKEN_SET_ID_PREFIX, DEFAULT_TREE_ID_PREFIX, DEFAULT_TREE_NETWORK_GROUP_ID_PREFIX, DEFAULT_TREE_NETWORK_SET_ID_PREFIX, JPHYLOIO_ATTRIBUTES_NAMESPACE, JPHYLOIO_ATTRIBUTES_PREFIX, JPHYLOIO_DATA_TYPE_NAMESPACE, JPHYLOIO_DATA_TYPE_PREFIX, JPHYLOIO_FORMATS_NAMESPACE_PREFIX, JPHYLOIO_GENERAL_NAMESPACE, JPHYLOIO_NAMESPACE_PREFIX, JPHYLOIO_PREDICATE_NAMESPACE, JPHYLOIO_PREDICATE_PREFIX, PREDICATE_CHARACTER_COUNT, PREDICATE_EDGE_LENGTH, PREDICATE_EDGE_SOURCE_NODE, PREDICATE_EDGE_TARGET_NODE, PREDICATE_HAS_CUSTOM_XML, PREDICATE_HAS_LITERAL_METADATA, PREDICATE_HAS_RESOURCE_METADATA, PREDICATE_IS_CROSSLINK, PREDICATE_NAMESPACE_FOLDER, PREDICATE_PART_SEPERATOR, PREDICATE_SEQUENCE_COUNT, RESERVED_ID_PREFIX
Constructor and Description |
---|
AbstractEventReader(ReadWriteParameterMap parameters,
java.lang.String matchToken) |
Modifier and Type | Method and Description |
---|---|
void |
addEventListener(JPhyloIOEventListener listener)
Adds a
JPhyloIOEventListener to the reader that will be informed on all events generated by this reader (e.g. |
void |
close()
Closes the underlying document source (usually a stream).
|
protected P |
createStreamDataProvider()
This method is called in the constructor of
AbstractEventReader to initialize the stream
data provider that will be returned by getStreamDataProvider() . |
protected void |
fireEvent(JPhyloIOEvent event) |
protected java.util.Collection<JPhyloIOEvent> |
getCurrentEventCollection()
Returns the event collection that is currently used to take up new events.
|
protected LongIDManager |
getIDManager() |
JPhyloIOEvent |
getLastNonCommentEvent()
Returns the last event that has been returned by previous calls of
readNextEvent()
that was not a comment event. |
protected ReadWriteParameterMap |
getParameters() |
ParentEventInformation |
getParentInformation()
The returned object provides information on the start events fired by this reader until now.
|
JPhyloIOEvent |
getPreviousEvent()
Returns the event that has been returned by the previous call of
readNextEvent() . |
protected SequenceTokensEventManager |
getSequenceTokensEventManager()
Returns the manager object used by this instance to create
SequenceTokensEvent s. |
protected P |
getStreamDataProvider() |
protected java.util.Queue<JPhyloIOEvent> |
getUpcomingEvents()
Returns the queue to store events in, that shall be returned by upcoming calls of
next() . |
boolean |
hasNextEvent()
Checks if another event could be parsed from the underlying document.
|
protected boolean |
hasSpecialEventCollection()
Determines whether the current event collection is different from the queue of upcoming events.
|
protected boolean |
isBeforeFirstAccess()
Indicates whether there have been any previous calls of
readNextEvent() since the last call
of #reset() . |
JPhyloIOEvent |
next()
Returns the next event from the underlying document and moves one step forward.
|
JPhyloIOEvent |
nextOfType(java.util.Set<EventType> types)
Reads elements from the underlying stream until one of the specified is found or the end of the document is reached.
|
JPhyloIOEvent |
peek()
Returns the event from the underlying document that will be returned in the next call of
JPhyloIOEventReader.next()
without moving forward. |
protected abstract void |
readNextEvent()
Method to be implemented be inherited classes that adds at least one additional event (determined from
the underlying data source) to the event queue.
|
void |
removeEventListener(JPhyloIOEventListener listener)
Removes a
JPhyloIOEventListener from the reader. |
protected java.util.Collection<JPhyloIOEvent> |
resetCurrentEventCollection()
Removes the event collection at the top of the eventCollections stack and returns it.
|
protected java.util.Collection<JPhyloIOEvent> |
setCurrentEventCollection(java.util.Collection<JPhyloIOEvent> newCollection)
Adds a new current event collection to the stack.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getFormatID
public AbstractEventReader(ReadWriteParameterMap parameters, java.lang.String matchToken)
public ParentEventInformation getParentInformation()
getParentInformation
in interface JPhyloIOEventReader
protected P createStreamDataProvider()
AbstractEventReader
to initialize the stream
data provider that will be returned by getStreamDataProvider()
. Inherit classes that use
their own stream data provider implementation should overwrite this method.
This default implementation creates a new instance of ReaderStreamDataProvider
.
protected P getStreamDataProvider()
protected ReadWriteParameterMap getParameters()
protected java.util.Collection<JPhyloIOEvent> resetCurrentEventCollection()
protected java.util.Collection<JPhyloIOEvent> setCurrentEventCollection(java.util.Collection<JPhyloIOEvent> newCollection)
newCollection
- the new collection to take up new events from now onjava.lang.NullPointerException
- if newCollection
is null
protected java.util.Collection<JPhyloIOEvent> getCurrentEventCollection()
protected boolean hasSpecialEventCollection()
false
if getCurrentEventCollection()
returns the same instance as getUpcomingEvents()
or true
otherwiseprotected java.util.Queue<JPhyloIOEvent> getUpcomingEvents()
next()
.
Note that new events should generally be added to getCurrentEventCollection()
instead.
protected LongIDManager getIDManager()
protected SequenceTokensEventManager getSequenceTokensEventManager()
SequenceTokensEvent
s. Such events should
always be created using the returned object by inherited classes and never directly.null
)protected void fireEvent(JPhyloIOEvent event) throws java.io.IOException
java.io.IOException
public JPhyloIOEvent getPreviousEvent()
readNextEvent()
.getPreviousEvent
in interface JPhyloIOEventReader
null
if there was no previous call of readNextEvent()
JPhyloIOEventReader.getLastNonCommentEvent()
public JPhyloIOEvent getLastNonCommentEvent()
readNextEvent()
that was not a comment event.getLastNonCommentEvent
in interface JPhyloIOEventReader
null
if no non-comment event was returned until nowJPhyloIOEventReader.getPreviousEvent()
protected boolean isBeforeFirstAccess()
readNextEvent()
since the last call
of #reset()
.
This method in meant for internal use in readNextEvent()
.
true
if there were no previous calls, false
otherwisepublic boolean hasNextEvent() throws java.io.IOException
JPhyloIOEventReader
hasNextEvent
in interface JPhyloIOEventReader
true
if another event is waiting, false
if the end of the underlying document was reachedjava.io.IOException
public JPhyloIOEvent next() throws java.io.IOException
JPhyloIOEventReader
next
in interface JPhyloIOEventReader
java.io.IOException
- Implementing classes might throw additional exceptionspublic JPhyloIOEvent nextOfType(java.util.Set<EventType> types) throws java.io.IOException
JPhyloIOEventReader
nextOfType
in interface JPhyloIOEventReader
types
- a set of valid types to be returnednull
if end of the file was reached before an according
element was foundjava.io.IOException
- Implementing classes might throw additional exceptionspublic JPhyloIOEvent peek() throws java.io.IOException
JPhyloIOEventReader
JPhyloIOEventReader.next()
without moving forward.peek
in interface JPhyloIOEventReader
java.io.IOException
- Implementing classes might throw additional exceptionspublic void addEventListener(JPhyloIOEventListener listener)
JPhyloIOEventReader
JPhyloIOEventListener
to the reader that will be informed on all events generated by this reader (e.g. when
its #next()
method is called).
Registering listeners here allows to combine pull- and push-parsing in a single implementation. Note that
EventForwarder
will usually be more useful for sole push-parsing implementations.
Internal tool classes may also use this method to listen to events.
addEventListener
in interface JPhyloIOEventReader
listener
- the listener that shall be addedpublic void removeEventListener(JPhyloIOEventListener listener)
JPhyloIOEventReader
JPhyloIOEventListener
from the reader.removeEventListener
in interface JPhyloIOEventReader
listener
- the listener that shall be removedprotected abstract void readNextEvent() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
JPhyloIOEventReader
close
in interface JPhyloIOEventReader
java.io.IOException
- Implementing classes might throw different types of exceptions if the stream cannot
be closed properly