+ class compareByColor and method 'Sort'

This commit is contained in:
ekallin 2023-12-16 15:26:40 +04:00
parent 8fab9e1bb6
commit ae63529594
3 changed files with 20 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using ProjectElectricLocomotive.DrawingObjects; using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,9 +12,21 @@ namespace ProjectElectricLocomotive
{ {
public int Compare(DrawingLocomotive? x, DrawingLocomotive? y) 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;
} }
} }
} }

View File

@ -15,6 +15,8 @@ namespace ProjectElectricLocomotive.Generics
/// </summary> /// </summary>
public IEnumerable<T?> GetLocomotives => _collection.GetLocomotives(); public IEnumerable<T?> GetLocomotives => _collection.GetLocomotives();
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
//ширина/высота окна //ширина/высота окна
private readonly int _pictureWidth; private readonly int _pictureWidth;

View File

@ -16,6 +16,9 @@ namespace ProjectElectricLocomotive.Generics
/// Максимальное количество объектов в списке /// Максимальное количество объектов в списке
private readonly int _maxCount; private readonly int _maxCount;
public void SortSet(IComparer<T?> comparer) =>_places.Sort(comparer);
public SetGeneric(int count) public SetGeneric(int count)
{ {
_maxCount = count; _maxCount = count;