diff --git a/src/Avans.FlatGalaxy.Models/Galaxy.cs b/src/Avans.FlatGalaxy.Models/Galaxy.cs index 39d514b..3258a42 100644 --- a/src/Avans.FlatGalaxy.Models/Galaxy.cs +++ b/src/Avans.FlatGalaxy.Models/Galaxy.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using Avans.FlatGalaxy.Models.CelestialBodies; using Avans.FlatGalaxy.Models.CelestialBodies.States; @@ -42,6 +43,17 @@ public void Remove(CelestialBody celestialBody) _celestialBodies.Remove(celestialBody); } + public void MapNeighbours(IDictionary planetNeighbours) + { + foreach (var (planet, neighbours) in planetNeighbours) + { + foreach (var neighbour in neighbours) + { + planet.Neighbours.Add(CelestialBodies.OfType().First(b => b.Name == neighbour)); + } + } + } + public void OnCompleted() { throw new NotImplementedException(); diff --git a/src/Avans.FlatGalaxy.Persistence/Parsers/ConfigurationParserBase.cs b/src/Avans.FlatGalaxy.Persistence/Parsers/ConfigurationParserBase.cs index 36453e4..59c05fd 100644 --- a/src/Avans.FlatGalaxy.Persistence/Parsers/ConfigurationParserBase.cs +++ b/src/Avans.FlatGalaxy.Persistence/Parsers/ConfigurationParserBase.cs @@ -18,16 +18,5 @@ protected ConfigurationParserBase(ICelestialBodyFactory celestialBodyFactory) public abstract Galaxy Parse(string content); public abstract bool CanParse(string content); - - protected static void MapNeighbours(Galaxy galaxy, Dictionary planetNeighbours) - { - foreach (var (planet, neighbours) in planetNeighbours) - { - foreach (var neighbour in neighbours) - { - planet.Neighbours.Add(galaxy.CelestialBodies.OfType().First(b => b.Name == neighbour)); - } - } - } } } diff --git a/src/Avans.FlatGalaxy.Persistence/Parsers/CsvConfigurationParser.cs b/src/Avans.FlatGalaxy.Persistence/Parsers/CsvConfigurationParser.cs index 19129bc..14f38d4 100644 --- a/src/Avans.FlatGalaxy.Persistence/Parsers/CsvConfigurationParser.cs +++ b/src/Avans.FlatGalaxy.Persistence/Parsers/CsvConfigurationParser.cs @@ -56,7 +56,7 @@ public override Galaxy Parse(string content) } } - MapNeighbours(galaxy, planetNeighbours); + galaxy.MapNeighbours(planetNeighbours); return galaxy; } } diff --git a/src/Avans.FlatGalaxy.Persistence/Parsers/XmlConfigurationParser.cs b/src/Avans.FlatGalaxy.Persistence/Parsers/XmlConfigurationParser.cs index eabb8f4..c94f410 100644 --- a/src/Avans.FlatGalaxy.Persistence/Parsers/XmlConfigurationParser.cs +++ b/src/Avans.FlatGalaxy.Persistence/Parsers/XmlConfigurationParser.cs @@ -86,7 +86,7 @@ public override Galaxy Parse(string content) if (body is Planet planet) planetNeighbours.Add(planet, neighbours.ToArray()); } - MapNeighbours(galaxy, planetNeighbours); + galaxy.MapNeighbours(planetNeighbours); return galaxy; } }