Сравнение объектов
This commit is contained in:
parent
bf8276b02e
commit
16f4b21f94
@ -39,5 +39,57 @@ namespace AccordionBus
|
||||
public string GetInfo() => _bus?.GetDataForSave();
|
||||
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectBus(data.CreateDrawningBus());
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherBus = other as DrawningObjectBus;
|
||||
if (otherBus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var bus = _bus.Bus;
|
||||
var otherBusBus = otherBus._bus.Bus;
|
||||
if (bus.GetType() != otherBusBus.GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (bus.Speed != otherBusBus.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (bus.Weight != otherBusBus.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (bus.BodyColor != otherBusBus.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// проверка в случае продвинутого объекта
|
||||
if (bus is EntityAccordionBus entityAccordionBus && otherBusBus is EntityAccordionBus otherEntityAccordionBus)
|
||||
{
|
||||
if (entityAccordionBus.DopColor != otherEntityAccordionBus.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (entityAccordionBus.Compartment != otherEntityAccordionBus.Compartment)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (entityAccordionBus.RearviewMirror != otherEntityAccordionBus.RearviewMirror)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (entityAccordionBus.BusNumber != otherEntityAccordionBus.BusNumber)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace AccordionBus
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -13,7 +13,7 @@ namespace AccordionBus
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetBusesGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -11,7 +11,7 @@ namespace AccordionBus
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetBusesGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
@ -49,6 +49,11 @@ namespace AccordionBus
|
||||
/// <returns>Возвращает позицию вставленного объекта, либо -1 если его не удалось вставить</returns>
|
||||
public int Insert(T bus, int position)
|
||||
{
|
||||
// Проверка на уникальность
|
||||
if (_places.Contains(bus))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
//проверка позиции
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user