PIbd-23-Kondratev-N.D.-Gaso.../GasolineTanker/ProjectGasolineTanker/Generic/TruckCompareByColor.cs

34 lines
1.0 KiB
C#
Raw Permalink Normal View History

2024-10-03 01:46:41 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker.Generics
{
internal class TruckCompareByColor : IComparer<DrawingTruck>
{
public int Compare(DrawingTruck? x, DrawingTruck? y)
{
if (x == null || x.EntityTruck == null)
throw new ArgumentNullException(nameof(x));
if (y == null || y.EntityTruck == null)
throw new ArgumentNullException(nameof(y));
var xTruck = x.EntityTruck;
var yTruck = y.EntityTruck;
if (xTruck.BodyColor != yTruck.BodyColor)
return xTruck.BodyColor.Name.CompareTo(yTruck.BodyColor.Name);
var speedCompare = x.EntityTruck.Speed.CompareTo(y.EntityTruck.Speed);
if (speedCompare != 0)
return speedCompare;
return x.EntityTruck.Weight.CompareTo(y.EntityTruck.Weight);
}
}
}