T
- Sentence interface to be listened.public abstract class AbstractSentenceListener<T extends Sentence> extends Object implements SentenceListener
Abstract base class for typed listeners with automatic sentence type
resolving and casting. Extend this class to create a listener/handler for a
single sentence type and register it in
SentenceReader
.
Methods of SentenceListener
interface implemented by this class are
empty, except sentenceRead(SentenceEvent)
which detects the incoming
sentence parsers and casts them to correct interface before calling
sentenceRead(Sentence)
method.
SentenceReader
Constructor and Description |
---|
AbstractSentenceListener() |
Modifier and Type | Method and Description |
---|---|
void |
readingPaused()
Empty implementation.
|
void |
readingStarted()
Empty implementation.
|
void |
readingStopped()
Empty implementation.
|
void |
sentenceRead(SentenceEvent event)
Resolves the type of each received sentence parser and passes it to
sentenceRead(T) if the type matches the expected type
T . |
abstract void |
sentenceRead(T sentence)
Invoked when sentence of type
T has been read and parsed. |
public void readingPaused()
readingPaused
in interface SentenceListener
SentenceListener.readingPaused()
public void readingStarted()
readingStarted
in interface SentenceListener
SentenceListener.readingStarted()
public void readingStopped()
readingStopped
in interface SentenceListener
SentenceListener.readingStopped()
public abstract void sentenceRead(T sentence)
T
has been read and parsed.sentence
- Sentence of type T
.public void sentenceRead(SentenceEvent event)
Resolves the type of each received sentence parser and passes it to
sentenceRead(T)
if the type matches the expected type
T
.
This method may be overridden, but be sure to call
super.sentencerRead(SentenceEvent)
before or after your
additional event handling. However, for listeners that need to handle all
incoming sentences, it's recommended to directly implement the
SentenceListener
interface.
sentenceRead
in interface SentenceListener
event
- SentenceEvent containing the data.SentenceListener.sentenceRead(net.sf.marineapi.nmea.event.SentenceEvent)
Copyright (C) 2010-2015 Java Marine API authors. All Rights Reserved.