AddressMatch.Training.TrainMachine.GetTopPostionIndex C# (CSharp) Method

GetTopPostionIndex() private method

private GetTopPostionIndex ( List ElementList, List StateList ) : int
ElementList List
StateList List
return int
        private int GetTopPostionIndex(List<InsertElement> ElementList, List<State> StateList)
        {
            MatchHelper.Assert(ElementList.Count != StateList.Count,
                                                 @" FUCTION GetTopPostionIndex ERROR,
                                                         ElementList's Length not equal to StateList's Length   ");
            int index = -1;

            for (int i = 0; i < ElementList.Count; i++)
            {
                // is new place and  index = 0, inserted node is root
                if ((ElementList[i].Mode & PlaceMask) == (UInt16)InsertMode.NewPlace)
                {
                    index = i;
                    break;
                }
                if ((ElementList[i].Mode & PlaceMask) == (UInt16)InsertMode.OldPlace)
                {
                    if (StateList[i].NodeCount >1)
                    {
                        throw new TrainException(ElementList[i], "Top Insert position is multi-matched, insert failed");
                    }
                    else if (StateList[i].NodeCount == 0)
                    {
                        throw new TrainException(ElementList[i], "Top Insert position is non-matched, insert failed");
                    }
                    else
                    {
                        index = i + 1;
                        // continue loop
                        continue;
                    }
                }
                if ((ElementList[i].Mode & PlaceMask) == (UInt16)InsertMode.AutoPlace)
                {
                    if (StateList[i].NodeCount == 1)
                    {
                        index = i + 1;
                        continue;
                    }
                    else if (StateList[i].NodeCount > 1)
                    {
                        throw new TrainException(ElementList[i], "Insert element list is not sufficient, insert failed");
                    }
                    else if (StateList[i].NodeCount == 0)
                    {
                        index = i;
                        break;
                    }
                }

            }

            MatchHelper.Assert(index == -1,
                                     @" FUCTION GetTopPostionIndex ERROR,
                                                         judge position index error, skip all if statement  ");

            return index;
        }