类 AbstractSentenceListener<T extends Sentence>

java.lang.Object
net.sf.marineapi.nmea.event.AbstractSentenceListener<T>
类型参数:
T - Sentence interface to be listened.
所有已实现的接口:
EventListener, SentenceListener
直接已知子类:
AbstractAISMessageListener, AbstractUBXMessageListener, SentenceListenerExamples.GSAListener, TypedSentenceListenerExample

public abstract class AbstractSentenceListener<T extends Sentence> extends Object implements SentenceListener

Abstract listener for NMEA-0183 sentences. Extend this class to create a listener for a specific sentence type and register it in a SentenceReader. For listeners that need to handle all incoming sentences, it is recommended to implement the SentenceListener interface.

Recommended usage:

   class MyListener extends AbstractSentenceListener<GGASentence>
 

Notice that more advanced use of generics and inheritance may require using the AbstractSentenceListener(Class) constructor. For example, the following example won't work because of the generic types not being available at runtime:

   class MyListener<A, B extends Sentence> extends AbstractSentenceListener<B>
   ...
   MyListener<String, GGASentence> ml = new MyListener<>();
 

Methods of the SentenceListener interface implemented by this class are empty, except for sentenceRead(net.sf.marineapi.nmea.event.SentenceEvent) which is final and detects the incoming sentences and casts them in correct interface before calling the sentenceRead(net.sf.marineapi.nmea.sentence.Sentence) method. The other methods may be overridden as needed.

作者:
Kimmo Tuukkanen
另请参阅:
  • 构造器详细资料

    • AbstractSentenceListener

      public AbstractSentenceListener()
      Default constructor with automatic generic type resolving. Notice that the GenericTypeResolver may not always succeed.
      抛出:
      IllegalStateException - If the generic type cannot be resolved at runtime.
      另请参阅:
    • AbstractSentenceListener

      protected AbstractSentenceListener(Class<T> c)
      Constructor with explicit generic type parameter. This constructor may be used when the default constructor fails to resolve the generic type T at runtime.
      参数:
      c - Sentence type T to be listened.
      另请参阅:
  • 方法详细资料

    • sentenceRead

      public final void sentenceRead(SentenceEvent event)

      Invoked for all received sentences. Checks the type of each sentence and invokes the sentenceRead(net.sf.marineapi.nmea.sentence.Sentence) if it matches the listener's generic type T.

      This method has been declared final to ensure the correct filtering of sentences.

      指定者:
      sentenceRead 在接口中 SentenceListener
      参数:
      event - SentenceEvent containing the data.
    • sentenceRead

      public abstract void sentenceRead(T sentence)
      Invoked when sentence of type T is received.
      参数:
      sentence - Sentence of type T
    • readingPaused

      public void readingPaused()
      Empty implementation.
      指定者:
      readingPaused 在接口中 SentenceListener
    • readingStarted

      public void readingStarted()
      Empty implementation.
      指定者:
      readingStarted 在接口中 SentenceListener
    • readingStopped

      public void readingStopped()
      Empty implementation.
      指定者:
      readingStopped 在接口中 SentenceListener