diff --git a/Catamaran/BoatCompareByColor.cs b/Catamaran/BoatCompareByColor.cs index 8d8985c..b017b93 100644 --- a/Catamaran/BoatCompareByColor.cs +++ b/Catamaran/BoatCompareByColor.cs @@ -11,8 +11,44 @@ namespace Catamaran { public int Compare(IDrawingObject x, IDrawingObject y) { - // TODO реализовать логику сравнения - throw new NotImplementedException(); + // реализовать логику сравнения + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xBoat = x as DrawingObjectBoat; + var yBoat = y as DrawingObjectBoat; + if (xBoat == null && yBoat == null) + { + return 0; + } + if (xBoat == null && yBoat != null) + { + return 1; + } + if (xBoat != null && yBoat == null) + { + return -1; + } + int colorCompare = string.Compare(xBoat.GetBoat.Catamaran.BodyColor.Name, yBoat.GetBoat.Catamaran.BodyColor.Name); + if (colorCompare != 0) + { + return colorCompare; + } + var speedCompare = xBoat.GetBoat.Catamaran.Speed.CompareTo(yBoat.GetBoat.Catamaran.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xBoat.GetBoat.Catamaran.Weight.CompareTo(yBoat.GetBoat.Catamaran.Weight); } } }