Esempio n. 1
0
        private void moveOthers()
        {
            //when isNotFinished will be false, after all cards passed and no one moved to ordered map
            //then finish this loop
            bool isFinished = false;

            while (!isFinished)
            {
                int lenStart = _unorderedCards.Count;

                for (int x = 0; x < lenStart; x++)
                {
                    BoardingCardMdl card = _unorderedCards[0];
                    _unorderedCards.RemoveAt(0);

                    bool placed = tryPlaceInOrderedList(card);
                    if (!placed)
                    {
                        _unorderedCards.Add(card);
                    }
                }

                int lenEnd = _unorderedCards.Count;

                if (lenStart == lenEnd)
                {
                    isFinished = true;
                }
            }
        }
Esempio n. 2
0
        /*
         * boarding cards should be ordered like that:
         * CARD0: start: Barselona, end: Gerona
         * CARD1: start: Gerona, end: Paris
         * CARD2: start: Paris, end London
         *
         * Then:
         * a. if start of current card match end of any placed one: place current card AFTER that placed one
         * b. if end of current card match start of placed one: place current card BEFORE that placed one
         * c. if not match, then leave in unordered list
         */
        private bool tryPlaceInOrderedList(BoardingCardMdl aCard)
        {
            //search for matched start or end
            foreach (BoardingCardMdl placedCard in _mdl.pBoardingCards)
            {
                int ind = _mdl.pBoardingCards.IndexOf(placedCard);

                if (placedCard.pStartPoint.pName == aCard.pEndPoint.pName)
                {
                    //place before
                    _mdl.pBoardingCards.Insert(ind, aCard);
                    return(true);
                }
                else if (placedCard.pEndPoint.pName == aCard.pStartPoint.pName)
                {
                    //place after
                    ind++;

                    if (ind < _mdl.pBoardingCards.Count)
                    {
                        _mdl.pBoardingCards.Insert(ind, aCard);
                    }
                    else
                    {
                        _mdl.pBoardingCards.Add(aCard);
                    }

                    return(true);
                }
            }


            return(false);
        }
Esempio n. 3
0
        private void moveFirst()
        {
            BoardingCardMdl card = _unorderedCards[0];

            _unorderedCards.RemoveAt(0);

            _mdl.pBoardingCards.Add(card);
        }
Esempio n. 4
0
        public BoardingCardMdl create(VehicleType aVehicleType, String aVehicleNumber, String aSitNumber,
                                      TripPointMdl aStartPoint, TripPointMdl aEndPoint, String aDesc)
        {
            _mdl             = new BoardingCardMdl();
            _mdl.pController = this;

            _mdl.pVehicleType   = aVehicleType;
            _mdl.pVehicleNumber = aVehicleNumber;
            _mdl.pSeatNumber    = aSitNumber;
            _mdl.pStartPoint    = aStartPoint;
            _mdl.pEndPoint      = aEndPoint;

            _mdl.pDescription = aDesc;

            return(_mdl);
        }
Esempio n. 5
0
 public void addBoardingCard(BoardingCardMdl aCard)
 {
     _unorderedCards.Add(aCard);
 }