логикa сравнения

This commit is contained in:
VictoriaPresnyakova 2022-12-04 18:13:28 +04:00
parent 68170b1023
commit 9619d8ea89

View File

@ -11,8 +11,44 @@ namespace Catamaran
{ {
public int Compare(IDrawingObject x, IDrawingObject y) public int Compare(IDrawingObject x, IDrawingObject y)
{ {
// TODO реализовать логику сравнения // реализовать логику сравнения
throw new NotImplementedException(); if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xBoat = x as DrawingObjectBoat;
var yBoat = y as DrawingObjectBoat;
if (xBoat == null && yBoat == null)
{
return 0;
}
if (xBoat == null && yBoat != null)
{
return 1;
}
if (xBoat != null && yBoat == null)
{
return -1;
}
int colorCompare = string.Compare(xBoat.GetBoat.Catamaran.BodyColor.Name, yBoat.GetBoat.Catamaran.BodyColor.Name);
if (colorCompare != 0)
{
return colorCompare;
}
var speedCompare = xBoat.GetBoat.Catamaran.Speed.CompareTo(yBoat.GetBoat.Catamaran.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xBoat.GetBoat.Catamaran.Weight.CompareTo(yBoat.GetBoat.Catamaran.Weight);
} }
} }
} }