Class PayloadState<T>

java.lang.Object
org.ahocorasick.trie.PayloadState<T>

public class PayloadState<T>
extends Object

A state has various important tasks it must attend to:

  • success; when a character points to another state, it must return that state
  • failure; when a character has no matching state, the algorithm must be able to fall back on a state with less depth
  • emits; when this state is passed and keywords have been matched, the matches and their payloads must be 'emitted' so that they can be used later on.

The root state is special in the sense that it has no failure state; it cannot fail. If it 'fails' it will still parse the next character and start from the root node. This ensures that the algorithm always runs. All other states always have a fail state.

Author:
Daniel Beck
  • Constructor Details

    • PayloadState

      public PayloadState()
    • PayloadState

      public PayloadState​(int depth)
  • Method Details

    • nextState

      public PayloadState<T> nextState​(Character character)
    • nextStateIgnoreRootState

      public PayloadState<T> nextStateIgnoreRootState​(Character character)
    • addState

      public PayloadState<T> addState​(Character character)
    • getDepth

      public int getDepth()
    • addEmit

      public void addEmit​(Payload<T> payload)
      Adds a payload to be emitted for this state.
      Parameters:
      payload - to be emitted.
    • addEmit

      public void addEmit​(Collection<Payload<T>> emits)
      Adds a collection of payloads to be emitted for this state.
      Parameters:
      emits - Collection of payloads to be emitted.
    • emit

      public Collection<Payload<T>> emit()
      Returns a collection of emitted payloads for this state.
      Returns:
      Collection of emitted payloads.
    • failure

      public PayloadState<T> failure()
    • setFailure

      public void setFailure​(PayloadState<T> failState)
    • getStates

      public Collection<PayloadState<T>> getStates()
    • getTransitions

      public Collection<Character> getTransitions()