equtable class ready
This commit is contained in:
parent
25b458f9e9
commit
8fab9e1bb6
@ -4,9 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ProjectElectricLocomotive.DrawingObjects;
|
using ProjectElectricLocomotive.DrawingObjects;
|
||||||
using ProjectElectricLocomotive.Entities;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using ProjectElectricLocomotive.Entities;
|
||||||
|
|
||||||
namespace ProjectElectricLocomotive.Generics
|
namespace ProjectElectricLocomotive.Generics
|
||||||
{
|
{
|
||||||
@ -19,8 +18,37 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
|
|
||||||
if (y == null || y.EntityLocomotive == null)
|
if (y == null || y.EntityLocomotive == null)
|
||||||
throw new ArgumentNullException(nameof(y));
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<DrawingLocomotive?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingLocomotive? x, DrawingLocomotive? y)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<DrawingLocomotive?>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,12 +23,12 @@ namespace ProjectElectricLocomotive.Generics
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
public int Insert(T loco)
|
public int Insert(T loco, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
return Insert(loco, 0);
|
return Insert(loco, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T loco, int position)
|
public int Insert(T loco, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if(_places.Count >= _maxCount)
|
if(_places.Count >= _maxCount)
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
Loading…
Reference in New Issue
Block a user