ISEbd-22 Alimova M.S. Lab Work 08 #8
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
62
AirBomber/AirBomber/DrawningPlanesEquatables.cs
Normal file
62
AirBomber/AirBomber/DrawningPlanesEquatables.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber;
|
||||
|
||||
namespace AirBomber
|
||||
namespace AirBomber.Entities
|
||||
{
|
||||
public class EntityAirBomber : EntityAirPlane
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber;
|
||||
|
||||
namespace AirBomber
|
||||
namespace AirBomber.Entities
|
||||
{
|
||||
public class EntityAirPlane
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user