PIbd - 21 Bakalskaya E.D. LabWork08 Base #10

Closed
ekallin wants to merge 6 commits from LabWork08 into LabWork07
4 changed files with 85 additions and 4 deletions
Showing only changes of commit 8fab9e1bb6 - Show all commits

View File

@ -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();
}
}
}

View File

@ -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)
{
Review

Требовалось сортировать по критериям: цвет, скорость, вес

Требовалось сортировать по критериям: цвет, скорость, вес
throw new NotImplementedException();
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);