Class StateMachineBuilder<TState, TInput, TResult>
- Namespace
- LfrlAnvil.Computable.Automata
- Assembly
- LfrlAnvil.Computable.Automata.dll
Represents a deterministic finite state machine builder.
public sealed class StateMachineBuilder<TState, TInput, TResult> where TState : notnull where TInput : notnull
Type Parameters
TState
State type.
TInput
Input type.
TResult
Result type.
- Inheritance
-
StateMachineBuilder<TState, TInput, TResult>
- Inherited Members
Constructors
StateMachineBuilder(TResult)
Creates a new empty StateMachineBuilder<TState, TInput, TResult> instance with Default state and input equality comparer.
public StateMachineBuilder(TResult defaultResult)
Parameters
defaultResult
TResultDefault transition result.
StateMachineBuilder(TResult, IEqualityComparer<TState>, IEqualityComparer<TInput>)
Creates a new empty StateMachineBuilder<TState, TInput, TResult> instance.
public StateMachineBuilder(TResult defaultResult, IEqualityComparer<TState> stateComparer, IEqualityComparer<TInput> inputComparer)
Parameters
defaultResult
TResultDefault transition result.
stateComparer
IEqualityComparer<TState>State equality comparer.
inputComparer
IEqualityComparer<TInput>Input equality comparer.
Properties
DefaultResult
Represents the default transition result.
public TResult DefaultResult { get; }
Property Value
- TResult
InputComparer
Input equality comparer.
public IEqualityComparer<TInput> InputComparer { get; }
Property Value
- IEqualityComparer<TInput>
Optimization
Specifies the chosen optimization parameters with which the state machine should be built.
public StateMachineOptimizationParams<TState> Optimization { get; }
Property Value
- StateMachineOptimizationParams<TState>
StateComparer
State equality comparer.
public IEqualityComparer<TState> StateComparer { get; }
Property Value
- IEqualityComparer<TState>
Methods
AddTransition(TState, TState, TInput, IStateTransitionHandler<TState, TInput, TResult>?)
Adds a new state transition.
public StateMachineBuilder<TState, TInput, TResult> AddTransition(TState source, TState destination, TInput input, IStateTransitionHandler<TState, TInput, TResult>? handler = null)
Parameters
source
TStateSource state.
destination
TStateDestination state.
input
TInputTransition identifier.
handler
IStateTransitionHandler<TState, TInput, TResult>Optional transition handler. Equal to null by default.
Returns
- StateMachineBuilder<TState, TInput, TResult>
this.
Remarks
States will be created if they don't exist.
Exceptions
- StateMachineTransitionException
When transition already exists.
AddTransition(TState, TInput, IStateTransitionHandler<TState, TInput, TResult>?)
Adds a new state self transition.
public StateMachineBuilder<TState, TInput, TResult> AddTransition(TState source, TInput input, IStateTransitionHandler<TState, TInput, TResult>? handler = null)
Parameters
source
TStateState to self transition to.
input
TInputTransition identifier.
handler
IStateTransitionHandler<TState, TInput, TResult>Optional transition handler. Equal to null by default.
Returns
- StateMachineBuilder<TState, TInput, TResult>
this.
Remarks
States will be created if they don't exist.
Exceptions
- StateMachineTransitionException
When transition already exists.
Build()
Creates a new StateMachine<TState, TInput, TResult> instance.
[Pure]
public StateMachine<TState, TInput, TResult> Build()
Returns
- StateMachine<TState, TInput, TResult>
New StateMachine<TState, TInput, TResult> instance.
Exceptions
- StateMachineCreationException
When an Initial state was not specified.
GetStates()
Creates a new IEnumerable<T> instance that contains all current states.
[Pure]
public IEnumerable<KeyValuePair<TState, StateMachineNodeType>> GetStates()
Returns
- IEnumerable<KeyValuePair<TState, StateMachineNodeType>>
New IEnumerable<T> instance.
GetTransitions(TState)
Creates a new IEnumerable<T> instance that contains all current transitions for the given state.
[Pure]
public IEnumerable<KeyValuePair<TInput, TState>> GetTransitions(TState source)
Parameters
source
TStateState to get all transitions for.
Returns
- IEnumerable<KeyValuePair<TInput, TState>>
New IEnumerable<T> instance or empty when state does not exist.
MarkAsAccept(TState)
Marks the given state
as Accept state.
public StateMachineBuilder<TState, TInput, TResult> MarkAsAccept(TState state)
Parameters
state
TStateState to mark as Accept.
Returns
- StateMachineBuilder<TState, TInput, TResult>
this.
Remarks
Creates a new state when it does not exist.
MarkAsDefault(TState)
Marks the given state
as Default state.
public StateMachineBuilder<TState, TInput, TResult> MarkAsDefault(TState state)
Parameters
state
TStateState to mark as Default.
Returns
- StateMachineBuilder<TState, TInput, TResult>
this.
Remarks
Creates a new state when it does not exist.
MarkAsInitial(TState)
Marks the given state
as Initial state.
public StateMachineBuilder<TState, TInput, TResult> MarkAsInitial(TState state)
Parameters
state
TStateState to mark as Initial.
Returns
- StateMachineBuilder<TState, TInput, TResult>
this.
Remarks
Creates a new state when it does not exist.
SetDefaultResult(TResult)
Sets DefaultResult of this instance.
public StateMachineBuilder<TState, TInput, TResult> SetDefaultResult(TResult value)
Parameters
value
TResultValue to set.
Returns
- StateMachineBuilder<TState, TInput, TResult>
this.
SetOptimization(StateMachineOptimizationParams<TState>)
Sets Optimization of this instance.
public StateMachineBuilder<TState, TInput, TResult> SetOptimization(StateMachineOptimizationParams<TState> value)
Parameters
value
StateMachineOptimizationParams<TState>Value to set.
Returns
- StateMachineBuilder<TState, TInput, TResult>
this.