Class Automaton.Transformer<B,R>
- Type Parameters:
B
- the behavior type in transformer resultsR
- the type of transformer results
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Map<Automaton.State,
B> The behavioral table for the result. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract B
makeBehavior
(Automaton.State oldState, Behavior<L, T> oldBehavior) Returns the behavior that the given behavior is transformed into.protected Automaton.State
makeState
(Automaton.State oldState) Returns the new state that the given old state is transformed into.protected final Automaton.State
transform
(Automaton.State oldState) Transforms a state and its associated behavior.transform
(BiFunction<Automaton.State, Map<Automaton.State, B>, ? extends R> cons) Transforms all reachable states of the automaton.
-
Field Details
-
newTable
The behavioral table for the result.
-
-
Constructor Details
-
Transformer
protected Transformer()
-
-
Method Details
-
transform
Transforms a state and its associated behavior.This method can be called multiple times, even recursively, with idempotent results. Results are cached such that a safe depth-first search of the automaton can be implemented straightforwardly.
- Parameters:
oldState
- the state to be transformed- Returns:
- the state that the given state is transformed into
-
makeState
Returns the new state that the given old state is transformed into.This method will be called exactly once for any state to be transformed. The default implementation creates a new state. Subclasses may override this method to reuse pre-existing states instead.
- Parameters:
oldState
- the state to be transformed- Returns:
- the state that the given state is transformed into
-
makeBehavior
Returns the behavior that the given behavior is transformed into.This method will be called exactly once for any state to be transformed. At that time, there will be no associated behavior in
newTable
. When this method returns, the result is added.Subclasses must implement this method. If the behavior contains references to old states, then these must be recursively transformed to new states according to
transform(State)
. Usually an expression of the formb.map(this::transform)
will do.- Parameters:
oldState
- the state to be transformedoldBehavior
- the behavior for the state to be transformed- Returns:
- the behavior that the given behavior is transformed into
-
transform
Transforms all reachable states of the automaton.A state t is directly reachable from state s if a reference to t occurs in the behavior associated with s. Indirect reachability is the reflexive-transitive closure of direct reachibility. A state is reachable if it is indirectly reachable from the initial state. Unreachable states are ignored by the transformation.
- Parameters:
cons
- the operation to construct the final result- Returns:
- the result of applying
cons
to the new initial state and behavioral table
-