diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocoEqutables.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocoEqutables.cs index 8e4bb74..ba97271 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocoEqutables.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/DrawingLocoEqutables.cs @@ -4,9 +4,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectElectricLocomotive.DrawingObjects; -using ProjectElectricLocomotive.Entities; using System.Diagnostics.CodeAnalysis; - +using ProjectElectricLocomotive.Entities; namespace ProjectElectricLocomotive.Generics { @@ -19,8 +18,37 @@ namespace ProjectElectricLocomotive.Generics if (y == null || y.EntityLocomotive == null) throw new ArgumentNullException(nameof(y)); + if (x.GetType().Name != y.GetType().Name) + return false; + if (x.EntityLocomotive.Speed != y.EntityLocomotive.Speed) + return false; + if (x.EntityLocomotive.Weight != y.EntityLocomotive.Weight) + return false; + if (x.EntityLocomotive.BodyColor != y.EntityLocomotive.BodyColor) + return false; + // to do logic for "сравнения" additional parameters :) + if (x is DrawingElectricLocomotive && y is DrawingElectricLocomotive) + { + if ((x.EntityLocomotive as EntityElectricLocomotive).AdditionalColor != (y.EntityLocomotive as EntityElectricLocomotive).AdditionalColor) + { + return false; + } + if ((x.EntityLocomotive as EntityElectricLocomotive).Horns != (y.EntityLocomotive as EntityElectricLocomotive).Horns) + { + return false; + } + if ((x.EntityLocomotive as EntityElectricLocomotive).SeifBatteries != (y.EntityLocomotive as EntityElectricLocomotive).SeifBatteries) + { + return false; + } + } + return true; + } + public int GetHashCode([DisallowNull] DrawingLocomotive obj) + { + return obj.GetHashCode(); } } } diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByColor.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByColor.cs new file mode 100644 index 0000000..5cf03f4 --- /dev/null +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByColor.cs @@ -0,0 +1,19 @@ +using ProjectElectricLocomotive.DrawingObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive +{ + internal class LocoCompareByColor : IComparer + { + public int Compare(DrawingLocomotive? x, DrawingLocomotive? y) + { + throw new NotImplementedException(); + + + } + } +} diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByType.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByType.cs new file mode 100644 index 0000000..13594e7 --- /dev/null +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocoCompareByType.cs @@ -0,0 +1,34 @@ +using ProjectElectricLocomotive.DrawingObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive +{ + internal class LocoCompareByType : IComparer + { + public int Compare(DrawingLocomotive? x, DrawingLocomotive? y) + { + if (x == null || x.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + var speedCompare = x.EntityLocomotive.Speed.CompareTo(y.EntityLocomotive.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityLocomotive.Weight.CompareTo(y.EntityLocomotive.Weight); + } + } +} diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs index ef88ca7..8728d67 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs @@ -23,12 +23,12 @@ namespace ProjectElectricLocomotive.Generics } /// Добавление объекта в набор - public int Insert(T loco) + public int Insert(T loco, IEqualityComparer? equal = null) { return Insert(loco, 0); } - public int Insert(T loco, int position) + public int Insert(T loco, int position, IEqualityComparer? equal = null) { if(_places.Count >= _maxCount) throw new StorageOverflowException(_maxCount);