Compare commits

...

2 Commits

8 changed files with 173 additions and 9 deletions

View File

@ -5,8 +5,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber;
using AirBomber.Entities;
namespace AirBomber
namespace AirBomber.DrawningObjects
{
public class DrawningAirBomber : DrawningAirPlane
{

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber;
using AirBomber.Entities;
namespace AirBomber
namespace AirBomber.DrawningObjects
{
public class DrawningAirPlane
{

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.DrawningObjects;
using AirBomber.Entities;
namespace AirBomber
{
internal class DrawningPlanesEquatables: IEqualityComparer<DrawningAirPlane?>
{
public bool Equals(DrawningAirPlane? x, DrawningAirPlane? y)
{
if (x == null || x.EntityAirPlane == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityAirPlane == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityAirPlane.Speed != y.EntityAirPlane.Speed)
{
return false;
}
if (x.EntityAirPlane.Weight != y.EntityAirPlane.Weight)
{
return false;
}
if (x.EntityAirPlane.BodyColor != y.EntityAirPlane.BodyColor)
{
return false;
}
if (x is DrawningAirBomber && y is DrawningAirBomber)
{
EntityAirBomber xAirBomber = (EntityAirBomber)x.EntityAirPlane;
EntityAirBomber yAirBomber = (EntityAirBomber)y.EntityAirPlane;
if (xAirBomber.Bombs != yAirBomber.Bombs)
return false;
if (xAirBomber.FuelTanks != yAirBomber.FuelTanks)
return false;
if (xAirBomber.AdditionalColor != yAirBomber.AdditionalColor)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawningAirPlane obj)
{
return obj.GetHashCode();
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using AirBomber;
namespace AirBomber
namespace AirBomber.Entities
{
public class EntityAirBomber : EntityAirPlane
{

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using AirBomber;
namespace AirBomber
namespace AirBomber.Entities
{
public class EntityAirPlane
{

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.DrawningObjects;
using AirBomber.Entities;
namespace AirBomber
{
internal class PlaneCompareByColor: IComparer<DrawningAirPlane?>
{
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
{
if (x == null || x.EntityAirPlane == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityAirPlane == null)
{
throw new ArgumentNullException(nameof(y));
}
var bodyColorCompare = x.EntityAirPlane.BodyColor.Name.CompareTo(y.EntityAirPlane.BodyColor.Name);
if (bodyColorCompare != 0)
{
return bodyColorCompare;
}
if (x.EntityAirPlane is EntityAirBomber xEntitySailCatamaran && y.EntityAirPlane is EntityAirBomber yEntitySailCatamaran)
{
var BodyColorCompare = xEntitySailCatamaran.BodyColor.Name.CompareTo(yEntitySailCatamaran.BodyColor.Name);
if (BodyColorCompare != 0)
{
return BodyColorCompare;
}
var AdditionalColorCompare = xEntitySailCatamaran.AdditionalColor.Name.CompareTo(yEntitySailCatamaran.AdditionalColor.Name);
if (AdditionalColorCompare != 0)
{
return AdditionalColorCompare;
}
}
var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight);
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.DrawningObjects;
namespace AirBomber.Generics
{
internal class PlaneCompareByType: IComparer<DrawningAirPlane?>
{
public int Compare(DrawningAirPlane? x, DrawningAirPlane? y)
{
if (x == null || x.EntityAirPlane == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityAirPlane == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight);
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using AirBomber.Exceptions;
namespace AirBomber
namespace AirBomber.Generics
{
internal class SetGeneric<T>
where T : class
@ -31,14 +31,15 @@ namespace AirBomber
_maxCount = count;
_places = new List<T?>(count);
}
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="plane">Добавляемый самолет</param>
/// <returns></returns>
public bool Insert(T plane)
public bool Insert(T plane, IEqualityComparer<T?>? equal = null)
{
return Insert(plane, 0);
return Insert(plane, 0, equal);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -46,13 +47,17 @@ namespace AirBomber
/// <param name="plane">Добавляемый самолет</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T plane, int position)
public bool Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
{
if (position < 0 || position >= _maxCount)
throw new StorageOverflowException("Невозможно добавить");
if (Count >= _maxCount)
throw new StorageOverflowException(_maxCount);
if (equal != null && _places.Contains(plane, equal))
throw new ArgumentException("Такой объект уже есть в коллекции");
_places.Insert(0, plane);
return true;
}