Compare commits
No commits in common. "a0a018477f27f43702a025a1532ca86838e74d65" and "fec308c18b3373aa0e703ce5d168d3e1ae0b1541" have entirely different histories.
a0a018477f
...
fec308c18b
@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTractor.DrawningObjects;
|
||||
using ProjectTractor.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ProjectTractor.Generics
|
||||
{
|
||||
internal class DrawiningTractorEqutables : IEqualityComparer<DrawningTractor?>
|
||||
{
|
||||
public bool Equals(DrawningTractor? x, DrawningTractor? y)
|
||||
{
|
||||
if (x == null || x.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTractor.Speed != y.EntityTractor.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTractor.Weight != y.EntityTractor.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTractor.BodyColor != y.EntityTractor.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningBulldoser && y is DrawningBulldoser)
|
||||
{
|
||||
// TODO доделать логику сравнения дополнительных параметров
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningTractor obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTractor.Exceptions;
|
||||
|
||||
namespace ProjectTractor.Generics
|
||||
{
|
||||
@ -32,21 +31,15 @@ namespace ProjectTractor.Generics
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T?> comparer) =>
|
||||
_places.Sort(comparer);
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="tractor">Добавляемый трактор</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T tractor, IEqualityComparer<T>? equal = null)
|
||||
public bool Insert(T tractor)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(tractor, 0, equal);
|
||||
return false;
|
||||
Insert(tractor, 0);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -55,29 +48,24 @@ namespace ProjectTractor.Generics
|
||||
/// <param name="tractor">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public void Insert(T tractor, int position, IEqualityComparer<T>? equal = null)
|
||||
public bool Insert(T tractor, int position)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (!(position >= 0 && position <= Count))
|
||||
throw new Exception("Неверная позиция для вставки");
|
||||
if (equal != null)
|
||||
{
|
||||
if (_places.Contains(tractor, equal))
|
||||
throw new ArgumentException(nameof(tractor));
|
||||
}
|
||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
return false;
|
||||
_places.Insert(position, tractor);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public void Remove(int position)
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
throw new TractorNotFoundException(position);
|
||||
return false;
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTractor.DrawningObjects;
|
||||
|
||||
namespace ProjectTractor.Generics
|
||||
{
|
||||
internal class TractorCompareByColor : IComparer<DrawningTractor?>
|
||||
{
|
||||
public int Compare(DrawningTractor? x, DrawningTractor? y)
|
||||
{
|
||||
if (x == null || x.EntityTractor == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityTractor == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
|
||||
if (x.EntityTractor.BodyColor.Name != y.EntityTractor.BodyColor.Name)
|
||||
{
|
||||
return x.EntityTractor.BodyColor.Name.CompareTo(y.EntityTractor.BodyColor.Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityTractor.Speed.CompareTo(y.EntityTractor.Speed);
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
|
||||
return x.EntityTractor.Weight.CompareTo(y.EntityTractor.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTractor.DrawningObjects;
|
||||
|
||||
namespace ProjectTractor.Generics
|
||||
{
|
||||
internal class TractorCompareByType : IComparer<DrawningTractor?>
|
||||
{
|
||||
public int Compare(DrawningTractor? x, DrawningTractor? y)
|
||||
{
|
||||
if (x == null || x.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityTractor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare =
|
||||
x.EntityTractor.Speed.CompareTo(y.EntityTractor.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityTractor.Weight.CompareTo(y.EntityTractor.Weight);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -55,12 +55,6 @@ namespace ProjectTractor.Generics
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T?> comparer) =>
|
||||
_collection.SortSet(comparer);
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
|
@ -139,12 +139,12 @@ namespace ProjectTractor
|
||||
string[] strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strings == null || strings.Length == 0)
|
||||
{
|
||||
throw new IOException("Нет данных для загрузки");
|
||||
throw new Exception("Нет данных для загрузки");
|
||||
}
|
||||
if (!strings[0].StartsWith("TractorStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new IOException("Неверный формат данных");
|
||||
throw new Exception("Неверный формат данных");
|
||||
}
|
||||
_tractorStorages.Clear();
|
||||
do
|
||||
@ -164,7 +164,7 @@ namespace ProjectTractor
|
||||
{
|
||||
if (!(collection + tractor))
|
||||
{
|
||||
throw new ArgumentNullException("Ошибка добавления в коллекцию");
|
||||
throw new Exception("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user