示例#1
0
        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);
        }
示例#2
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            CompositeState other = obj as CompositeState;

            if (other == null)
            {
                return(false);
            }

            return(Enumerable.SequenceEqual(this.states, other.states));
        }
示例#3
0
 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));
     }
 }
示例#4
0
        /// <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);
        }
示例#5
0
 public static State Create(State state1, State state2)
 {
     return(CompositeState.Create(state1, state2));
 }