From 12f8e6c8288460958299a93e0fa91ddfaa3d9b9b Mon Sep 17 00:00:00 2001 From: insideq Date: Thu, 16 May 2024 11:36:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D1=83=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionGenericObjects/ICollectionGenericObjects.cs | 4 ++-- .../CollectionGenericObjects/ListGenericObjects.cs | 8 ++++---- .../CollectionGenericObjects/MassiveGenericObjects.cs | 8 ++++---- .../Exceptions/CollectionAlreadyExistsException.cs | 2 +- .../ProjectExcavator/FormBulldozerCollection.cs | 5 +++++ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs index f0b6a0d..81be154 100644 --- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -25,7 +25,7 @@ public interface ICollectionGenericObjects /// Добавляемый объект /// Сравнение двух объектов /// true - вставка прошла успешно, false - вставка не удалась - int Insert(T obj, IEqualityComparer? comparer = null); + int Insert(T obj, IEqualityComparer? comparer = null); /// /// Добавление элемента в коллекцию на конкретную позицию @@ -34,7 +34,7 @@ public interface ICollectionGenericObjects /// Позиция /// Сравнение двух объектов /// true - вставка прошла успешно, false - вставка не удалась - int Insert(T obj, int position, IEqualityComparer? comparer = null); + int Insert(T obj, int position, IEqualityComparer? comparer = null); /// /// Удаление объекта из коллекции с конкретной позиции diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs index 8128aae..4216665 100644 --- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs @@ -39,10 +39,10 @@ public class ListGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj, IEqualityComparer? comparer = null) + public int Insert(T obj, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } @@ -56,10 +56,10 @@ public class ListGenericObjects : ICollectionGenericObjects return _maxCount; } - public int Insert(T obj, int position, IEqualityComparer? comparer = null) + public int Insert(T obj, int position, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs index 4837898..52b94b5 100644 --- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs @@ -61,10 +61,10 @@ public class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj, IEqualityComparer? comparer = null) + public int Insert(T obj, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } @@ -82,11 +82,11 @@ public class MassiveGenericObjects : ICollectionGenericObjects throw new CollectionOverflowException(Count); } - public int Insert(T obj, int position, IEqualityComparer? comparer = null) + public int Insert(T obj, int position, IEqualityComparer? comparer = null) { // TODO выброс ошибки, если такой объект есть в коллекции - if (comparer != null && _collection.Contains(obj)) + if (comparer != null && _collection.Contains(obj, comparer)) { throw new CollectionAlreadyExistsException(); } diff --git a/ProjectExcavator/ProjectExcavator/Exceptions/CollectionAlreadyExistsException.cs b/ProjectExcavator/ProjectExcavator/Exceptions/CollectionAlreadyExistsException.cs index 9476edf..bce663e 100644 --- a/ProjectExcavator/ProjectExcavator/Exceptions/CollectionAlreadyExistsException.cs +++ b/ProjectExcavator/ProjectExcavator/Exceptions/CollectionAlreadyExistsException.cs @@ -10,7 +10,7 @@ namespace ProjectExcavator.Exceptions; internal class CollectionAlreadyExistsException : ApplicationException { public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base("В коллекции уже есть такой элемент: " + collectionInfo) { } - public CollectionAlreadyExistsException() : base() { } + public CollectionAlreadyExistsException() : base("В коллекции уже есть такой элемент") { } public CollectionAlreadyExistsException(string message) : base(message) { } public CollectionAlreadyExistsException(string message, Exception exception) : base(message, exception) { } protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { } diff --git a/ProjectExcavator/ProjectExcavator/FormBulldozerCollection.cs b/ProjectExcavator/ProjectExcavator/FormBulldozerCollection.cs index 4eecfb3..9812485 100644 --- a/ProjectExcavator/ProjectExcavator/FormBulldozerCollection.cs +++ b/ProjectExcavator/ProjectExcavator/FormBulldozerCollection.cs @@ -82,6 +82,11 @@ public partial class FormBulldozerCollection : Form MessageBox.Show(ex.Message); _logger.LogError("Ошибка: {Message}", ex.Message); } + catch (CollectionAlreadyExistsException ex) + { + MessageBox.Show(ex.Message); + _logger.LogError("Ошибка: {Message}", ex.Message); + } } private void ButtonRemoveCar_Click(object sender, EventArgs e)