PIbd - 21 Bakalskaya E.D. LabWork08 Base #10
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
public int Insert(T loco, int position)
|
||||
public int Insert(T loco, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if(_places.Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
Loading…
Reference in New Issue
Block a user
Требовалось сортировать по критериям: цвет, скорость, вес