internal static IDictionary <char, State> Merge(params IDictionary <char, State>[] states) { IDictionary <char, State> set = null; for (int i = 0, ii = states.Length; i < ii; i++) { IDictionary <char, State> state = states[i]; if (state != null && state.Count > 0) { if (set == null) { set = state; } else { foreach (State s2 in state.Values) { State s1; if (set.TryGetValue(s2.Char, out s1)) { set[s2.Char] = CompositeState.Create(s1, s2); } else { set[s2.Char] = s2; } } } } } return(set); }
public static State Create(State state1, State state2, State state3) { if (state1 != null) { if (state2 != null && state2 != state1) { return(state3 != null && state3 != state2 && state3 != state1 ? new CompositeState(state1, state2, state3) : new CompositeState(state1, state2)); } else { return(CompositeState.Create(state1, state3)); } } else { return(CompositeState.Create(state2, state3)); } }
/// <inheritdoc /> public override IDictionary <char, State> NextStates() { if (this.nextstates == null) { IDictionary <char, State> set = null; IList <State> s = this.states; for (int i = 0, ii = s.Count; i < ii; i++) { IDictionary <char, State> nextStates = s[i].NextStates(); if (set == null) { set = nextStates; } else { foreach (State s2 in nextStates.Values) { State s1; if (set.TryGetValue(s2.Char, out s1)) { set[s2.Char] = CompositeState.Create(s1, s2); } else { set[s2.Char] = s2; } } } } this.nextstates = set; } return(this.nextstates); }
public static State Create(State state1, State state2) { return(CompositeState.Create(state1, state2)); }