Package org.ahocorasick.trie
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 Summary
Constructors Constructor Description PayloadState()
PayloadState(int depth)
-
Method Summary
Modifier and Type Method Description void
addEmit(Collection<Payload<T>> emits)
Adds a collection of payloads to be emitted for this state.void
addEmit(Payload<T> payload)
Adds a payload to be emitted for this state.PayloadState<T>
addState(Character character)
Collection<Payload<T>>
emit()
Returns a collection of emitted payloads for this state.PayloadState<T>
failure()
int
getDepth()
Collection<PayloadState<T>>
getStates()
Collection<Character>
getTransitions()
PayloadState<T>
nextState(Character character)
PayloadState<T>
nextStateIgnoreRootState(Character character)
void
setFailure(PayloadState<T> failState)
-
Constructor Details
-
PayloadState
public PayloadState() -
PayloadState
public PayloadState(int depth)
-
-
Method Details
-
nextState
-
nextStateIgnoreRootState
-
addState
-
getDepth
public int getDepth() -
addEmit
Adds a payload to be emitted for this state.- Parameters:
payload
- to be emitted.
-
addEmit
Adds a collection of payloads to be emitted for this state.- Parameters:
emits
- Collection of payloads to be emitted.
-
emit
Returns a collection of emitted payloads for this state.- Returns:
- Collection of emitted payloads.
-
failure
-
setFailure
-
getStates
-
getTransitions
-