Exemple #1
0
        public StationRelation AddRelation(Station from, Station to, int timespan)
        {
            if (from == to)
            {
                throw new ArgumentException($"Argument \"{nameof(from)}\" is equals to argument \"{nameof(to)}\"");
            }
            if (from.Line.Scheme != this ||
                to.Line.Scheme != this)
            {
                throw new ArgumentException();
            }

            var result = new StationRelation(from, to, timespan);

            // Добавляется пересадка между линиями метро
            if (from.Line != to.Line)
            {
                AddLineRelation(result);
            }

            // Все связи считаются двусторонними, добавляются дважды в коллекцию StationRelations
            AddStationRelation(from, result);
            AddStationRelation(to, result);

            return(result);
        }
Exemple #2
0
        private void AddLineRelation(StationRelation relation)
        {
            if (relation.From.Line == relation.To.Line)
            {
                throw new ArgumentException();
            }

            ISet <Station> r1;

            if (!LineRelationStations.TryGetValue(relation.From.Line, out r1))
            {
                r1 = new HashSet <Station>();
                LineRelationStations.Add(relation.From.Line, r1);
            }
            r1.Add(relation.From);

            ISet <Station> r2;

            if (!LineRelationStations.TryGetValue(relation.To.Line, out r2))
            {
                r2 = new HashSet <Station>();
                LineRelationStations.Add(relation.To.Line, r2);
            }
            r2.Add(relation.To);
        }
Exemple #3
0
        private void AddStationRelation(Station station, StationRelation relation)
        {
            ICollection <StationRelation> r;

            if (!StationRelations.TryGetValue(station, out r))
            {
                r = new List <StationRelation>();
                StationRelations.Add(station, r);
            }
            r.Add(relation);
        }
Exemple #4
0
        /// <summary>
        /// Добавление маршрута в конец текущего (с автоповоротом добавляемого маршрута)
        /// </summary>
        /// <param name="route">Добавляемый маршрут</param>
        public void AddLast(IRoute route)
        {
            // Определение необходимости разворота маршрута
            bool reverse;

            if (route.To == To)
            {
                reverse = true;
            }
            else if (route.From == To)
            {
                reverse = false;
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(route));
            }

            if (route.Length == 2)
            {
                route   = new StationRelation(To, (reverse) ? route.From : route.To, route.Timespan);
                reverse = false;
            }

            var newNode = new RouteNode
            {
                Route      = route,
                IsReversed = reverse,
                Next       = null,
                Prior      = Last
            };

            Last.Next = newNode;
            Last      = newNode;

            OnAddRoute(route);
        }