57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Diagnostics.CodeAnalysis;
|
|||
|
using ContainerShip.Entities;
|
|||
|
using ContainerShip.DrawningObjects;
|
|||
|
|
|||
|
namespace ContainerShip.Generic
|
|||
|
{
|
|||
|
internal class DrawningShipEqutables : 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 DrawingContainerShip && y is DrawingContainerShip)
|
|||
|
{
|
|||
|
var xPlane = (EntityContainerShip)x.EntityShip;
|
|||
|
var yPlane = (EntityContainerShip)y.EntityShip;
|
|||
|
|
|||
|
if (xPlane.AdditionalColor != yPlane.AdditionalColor)
|
|||
|
return false;
|
|||
|
|
|||
|
if (xPlane.Load != yPlane.Load)
|
|||
|
return false;
|
|||
|
|
|||
|
if (xPlane.Crane != yPlane.Crane)
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public int GetHashCode([DisallowNull] DrawningShip? obj)
|
|||
|
{
|
|||
|
return obj.GetHashCode();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|