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 { 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); } } }