diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByColor.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByColor.cs index 5cf03f4..e27ae5c 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByColor.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByColor.cs @@ -1,4 +1,5 @@ using ProjectElectricLocomotive.DrawingObjects; +using ProjectElectricLocomotive.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -11,9 +12,21 @@ namespace ProjectElectricLocomotive { public int Compare(DrawingLocomotive? x, DrawingLocomotive? y) { - throw new NotImplementedException(); - + if (x == null || x.EntityLocomotive == null) + throw new NotImplementedException(nameof(x)); + if (y == null || y.EntityLocomotive == null) + throw new NotImplementedException(nameof(y)); + var bodyColor = x.EntityLocomotive.BodyColor.Name.CompareTo(y.EntityLocomotive.BodyColor.Name); + if (bodyColor != 0) return bodyColor; + if(x.EntityLocomotive is EntityElectricLocomotive xEntityElectricLocomotive && + y.EntityLocomotive is EntityElectricLocomotive yEntityElectricLocomotive) + { + var addcolor = (x.EntityLocomotive as EntityElectricLocomotive).AdditionalColor.Name.CompareTo( + (y.EntityLocomotive as EntityElectricLocomotive).AdditionalColor.Name); + if(addcolor != 0) return addcolor; + } + return 1; } } } diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs index 70aea37..9f76e4f 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs @@ -15,6 +15,8 @@ namespace ProjectElectricLocomotive.Generics /// public IEnumerable GetLocomotives => _collection.GetLocomotives(); + public void Sort(IComparer comparer) => _collection.SortSet(comparer); + //ширина/высота окна private readonly int _pictureWidth; diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs index 8728d67..12c42d7 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs @@ -16,6 +16,9 @@ namespace ProjectElectricLocomotive.Generics /// Максимальное количество объектов в списке private readonly int _maxCount; + + public void SortSet(IComparer comparer) =>_places.Sort(comparer); + public SetGeneric(int count) { _maxCount = count;