public AstronomicalChart Build(string input)
        {
            input = input.Trim();
            var commands = Split(input).ToList();
            var objects  = new Dictionary <string, AstronomicalObject>();

            AstronomicalChart result = null;

            foreach (var command in commands)
            {
                AstronomicalObject primary;
                if (!objects.TryGetValue(command.Item1, out primary))
                {
                    primary = new AstronomicalObject(command.Item1);
                    objects.Add(primary.Name, primary);
                }

                if (result == null && primary.Name == "COM")
                {
                    result = new AstronomicalChart(primary);
                }

                AstronomicalObject satellite;
                if (!objects.TryGetValue(command.Item2, out satellite))
                {
                    satellite = new AstronomicalObject(command.Item2);
                    objects.Add(satellite.Name, satellite);
                }

                primary.AddSatellite(satellite);
            }

            return(result);
        }
예제 #2
0
 public AstronomicalRouteFinder(AstronomicalChart chart)
 {
     _chart = chart ?? throw new ArgumentNullException(nameof(chart));
 }