From 00492b0693203da9e71beaa01ca4c1cb7a574842 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Wed, 20 Mar 2024 16:01:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=82=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=84=D0=BE=D1=80=D0=BC=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 10 +++--- .../ICollectionGenericObjects.cs | 14 +++++---- .../MassiveGenericObjects.cs | 31 +++++++++++-------- .../FormAirplaneCollection.cs | 4 +-- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/AbstractCompany.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/AbstractCompany.cs index a95236d..7ba7477 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/AbstractCompany.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/AbstractCompany.cs @@ -57,9 +57,9 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects /// Компания /// Добавляемый объект /// - public static bool operator +(AbstractCompany company, DrawningAirplane airplane) + public static int operator +(AbstractCompany company, DrawningAirplane airplane) { - return company._collection?.Insert(airplane) ?? false; + return company._collection.Insert(airplane); } /// @@ -68,10 +68,10 @@ namespace ProjectAirplaneWithRadar.CollectionGenericObjects /// Компания /// Номер удаляемого объекта /// - public static bool operator -(AbstractCompany company, int position) + public static DrawningAirplane operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; - } + return company._collection.Remove(position); + } /// /// Получение случайного объекта из коллекции diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/ICollectionGenericObjects.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/ICollectionGenericObjects.cs index c73b98d..70cfa58 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,4 +1,6 @@ -namespace ProjectAirplaneWithRadar.CollectionGenericObjects +using ProjectAirplaneWithRadar.Drawnings; + +namespace ProjectAirplaneWithRadar.CollectionGenericObjects { /// /// Интерфейс описания действий для набора хранимых объектов @@ -22,22 +24,22 @@ /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию /// /// Добавляемый объект /// Позиция - /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj, int position); + /// 1 - вставка прошла удачно, -1 - вставка не удалась + int Insert(T obj, int position); /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция - /// true - удаление прошло удачно, false - удаление не удалось - bool Remove(int position); + /// + T? Remove(int position); /// /// Получение объекта по позиции diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/MassiveGenericObjects.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/MassiveGenericObjects.cs index 9b09530..3ba4420 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/CollectionGenericObjects/MassiveGenericObjects.cs @@ -47,28 +47,28 @@ return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { for(int i = 0; i < Count; i++) { if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } - return false; + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { if (position < 0 || position >= Count) - return false; + return -1; if (_collection[position] == null) { _collection[position] = obj; - return true; + return position; } int temp = position + 1; @@ -77,7 +77,7 @@ if (_collection[temp] == null) { _collection[temp] = obj; - return true; + return temp; } temp++; } @@ -88,22 +88,27 @@ if (_collection[temp] == null) { _collection[temp] = obj; - return true; + return temp; } temp--; } - return false; + return -1; } - public bool Remove(int position) + public T? Remove(int position) { if (position < 0 || position >= Count) - return false; + return null; + if(_collection[position] == null) + { + return null; + } + + T? temp = _collection[position]; _collection[position] = null; - - return true; + return temp; } } } diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneCollection.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneCollection.cs index 2afd965..5c5399c 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneCollection.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneCollection.cs @@ -64,7 +64,7 @@ namespace ProjectAirplaneWithRadar return; } - if (_company + drawingAirplane) + if (_company + drawingAirplane != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -124,7 +124,7 @@ namespace ProjectAirplaneWithRadar } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show();