From 5c7b6d8bf223a03124f371e0a33becbc78c41679 Mon Sep 17 00:00:00 2001 From: gettterot Date: Mon, 10 Jun 2024 05:54:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=20DrawningLinerCompareByType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 4 +- .../Drawnings/DrawningLinerCompareByType.cs | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 ProjectLiner/ProjectLiner/Drawnings/DrawningLinerCompareByType.cs diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs index c85dc44..3ccc120 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs @@ -60,9 +60,9 @@ namespace ProjectLiner.CollectionGenericObjects /// Компания /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningCommonLiner airplane) + public static int operator +(AbstractCompany company, DrawningCommonLiner liner) { - return company._collection.Insert(airplane); + return company._collection.Insert(liner, new DrawningLinerEqutables() ); } /// diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawningLinerCompareByType.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningLinerCompareByType.cs new file mode 100644 index 0000000..55584e5 --- /dev/null +++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningLinerCompareByType.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectLiner.Drawnings; +/// +/// Сравнение по типу, скорости, весу +/// +public class DrawningLinerCompareByType : IComparer +{ + + public int Compare(DrawningCommonLiner? x, DrawningCommonLiner? y) + { + if (x == null && y == null) return 0; + if (x == null || x.EntityCommonLiner == null) + { + return 1; + } + + if (y == null || y.EntityCommonLiner == null) + { + return -1; + } + + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + + var speedCompare = x.EntityCommonLiner.Speed.CompareTo(y.EntityCommonLiner.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + + return x.EntityCommonLiner.Weight.CompareTo(y.EntityCommonLiner.Weight); + } +}