From 8b2e357a8a3a825ed78a216186195992f1d68abd Mon Sep 17 00:00:00 2001 From: Ivan_Starostin Date: Fri, 22 Dec 2023 19:05:09 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lainer/Lainer1/DrawingLainerEqutables.cs | 56 ++++++++++++++++++++++++ lainer/Lainer1/LainerCompareByColor.cs | 34 ++++++++++++++ lainer/Lainer1/LainerCompareByType.cs | 28 ++++++++++++ lainer/Lainer1/LainersCollectionInfo.cs | 21 +++++++++ 4 files changed, 139 insertions(+) create mode 100644 lainer/Lainer1/DrawingLainerEqutables.cs create mode 100644 lainer/Lainer1/LainerCompareByColor.cs create mode 100644 lainer/Lainer1/LainerCompareByType.cs create mode 100644 lainer/Lainer1/LainersCollectionInfo.cs diff --git a/lainer/Lainer1/DrawingLainerEqutables.cs b/lainer/Lainer1/DrawingLainerEqutables.cs new file mode 100644 index 0000000..6b98db1 --- /dev/null +++ b/lainer/Lainer1/DrawingLainerEqutables.cs @@ -0,0 +1,56 @@ +using ProjectLainer.DrawningObjects; +using ProjectLainer.Entities; +using System.Diagnostics.CodeAnalysis; +namespace ProjectLainer.Generics +{ + internal class DrawiningLainerEqutables : IEqualityComparer + { + public bool Equals(DrawingEntity? x, DrawingEntity? y) + { + if (x == null || x.EntityLainer == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityLainer == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + if (x.EntityLainer.Speed != y.EntityLainer.Speed) + { + return false; + } + if (x.EntityLainer.Weight != y.EntityLainer.Weight) + { + return false; + } + if (x.EntityLainer.BodyColor != y.EntityLainer.BodyColor) + { + return false; + } + if (x is DrawningSuperLainer && y is DrawningSuperLainer) + { + EntitySuperLainer entityX = (EntitySuperLainer)x.EntityLainer; + EntitySuperLainer entityY = (EntitySuperLainer)y.EntityLainer; + if(entityX.Pools != entityY.Pools) + { + return false; + } + if(entityX.Decks != entityY.Decks) + { + return false; + } + if(entityX.AdditionalColor != entityY.AdditionalColor) { return false; } + } + return true; + } + public int GetHashCode([DisallowNull] DrawingEntity obj) + { + return obj.GetHashCode(); + } + } +} + diff --git a/lainer/Lainer1/LainerCompareByColor.cs b/lainer/Lainer1/LainerCompareByColor.cs new file mode 100644 index 0000000..c67e051 --- /dev/null +++ b/lainer/Lainer1/LainerCompareByColor.cs @@ -0,0 +1,34 @@ +using ProjectLainer.DrawningObjects; +using ProjectLainer.Entities; + +namespace ProjectLainer.Generics +{ + internal class LainerCompareByColor : IComparer + { + public int Compare(DrawingEntity? x, DrawingEntity? y) + { + if (x == null || x.EntityLainer == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityLainer == null) + { + throw new ArgumentNullException(nameof(y)); + } + //по цвету + var colorCompare = x.EntityLainer.BodyColor.Name.CompareTo(y.EntityLainer.BodyColor.Name); + if(colorCompare != 0) + { + return colorCompare; + } + //по скорости + var speedCompare = x.EntityLainer.Speed.CompareTo(y.EntityLainer.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + //по весу + return x.EntityLainer.Weight.CompareTo(y.EntityLainer.Weight); + } + } +} diff --git a/lainer/Lainer1/LainerCompareByType.cs b/lainer/Lainer1/LainerCompareByType.cs new file mode 100644 index 0000000..4a94a92 --- /dev/null +++ b/lainer/Lainer1/LainerCompareByType.cs @@ -0,0 +1,28 @@ +using ProjectLainer.DrawningObjects; +namespace ProjectLainer.Generics +{ + internal class LainerCompareByType : IComparer + { + public int Compare(DrawingEntity? x, DrawingEntity? y) + { + if (x == null || x.EntityLainer == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityLainer == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + var speedCompare = x.EntityLainer.Speed.CompareTo(y.EntityLainer.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityLainer.Weight.CompareTo(y.EntityLainer.Weight); + } + } +} diff --git a/lainer/Lainer1/LainersCollectionInfo.cs b/lainer/Lainer1/LainersCollectionInfo.cs new file mode 100644 index 0000000..b23c511 --- /dev/null +++ b/lainer/Lainer1/LainersCollectionInfo.cs @@ -0,0 +1,21 @@ +namespace ProjectLainer.Generics +{ + internal class LainersCollectionInfo : IEquatable + { + public string Name { get; private set; } + public string Description { get; private set; } + public LainersCollectionInfo(string name, string description) + { + Name = name; + Description = description; + } + public bool Equals(LainersCollectionInfo? other) + { + if(other!= null) + { + return this.Name == other.Name; + } + return false; + } + } +}