PIbd-23_Dolgova_D.N._Warmly.../WarmlyShip/Generics/DrawiningShipEqutables.cs
2023-12-30 13:14:20 +04:00

67 lines
1.9 KiB
C#

using WarmlyShip.DrawningObjects;
using WarmlyShip.Entities;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WarmlyShip.Generics
{
internal class DrawiningShipEqutables : 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 DrawningWarmlyShip && y is DrawningWarmlyShip)
{
EntityWarmlyShip EntityX = (EntityWarmlyShip)x.EntityShip;
EntityWarmlyShip EntityY = (EntityWarmlyShip)y.EntityShip;
if (EntityX.Pipe != EntityY.Pipe)
{
return false;
}
if (EntityX.FuelCompartment != EntityY.FuelCompartment)
{
return false;
}
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
{
return false;
}
}
return true;
}
public int GetHashCode([DisallowNull] DrawningShip? obj)
{
return obj.GetHashCode();
}
}
}