60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using ProjectContainerShip.DrawningObjects;
|
|
using ProjectContainerShip;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ProjectContainerShip.Entities;
|
|
|
|
namespace ContainerShip.Generics
|
|
{
|
|
internal class DrawningContainerShipEqutables : IEqualityComparer<DrawningShip?>
|
|
{
|
|
public bool Equals(DrawningShip? x, DrawningShip? y)
|
|
{
|
|
if (x == null || x.EntityShip == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(x));
|
|
}
|
|
if (y == null || y.EntityShip == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(y));
|
|
}
|
|
if (x.GetType().Name != y.GetType().Name)
|
|
{
|
|
return false;
|
|
}
|
|
if (x.EntityShip.Speed != y.EntityShip.Speed)
|
|
{
|
|
return false;
|
|
}
|
|
if (x.EntityShip.Weight != y.EntityShip.Weight)
|
|
{
|
|
return false;
|
|
}
|
|
if (x.EntityShip.BodyColor != y.EntityShip.BodyColor)
|
|
{
|
|
return false;
|
|
}
|
|
if (x is EntityContainerShip && y is EntityContainerShip)
|
|
{
|
|
EntityContainerShip EntityX = (EntityContainerShip)x.EntityShip;
|
|
EntityContainerShip EntityY = (EntityContainerShip)y.EntityShip;
|
|
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
|
return false;
|
|
if (EntityX.Crane != EntityY.Crane)
|
|
return false;
|
|
if (EntityX.Container != EntityY.Container)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public int GetHashCode([DisallowNull] DrawningShip obj)
|
|
{
|
|
return obj.GetHashCode();
|
|
}
|
|
}
|
|
}
|