From d3dfa6670f441f399ff2c74fbcac6b5f689fa020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=20=D0=9F=D0=B5=D1=80=D0=BC=D1=8F?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= Date: Mon, 11 Mar 2024 14:37:22 +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=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 8 +++--- .../ICollectionGenericObjects.cs | 6 ++--- .../MassiveGenericObjects.cs | 25 ++++++++++--------- .../AccordionBus/FormBusCollection.cs | 4 +-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs index 23479f1..2a77699 100644 --- a/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs @@ -29,14 +29,14 @@ namespace AccordionBus.CollectionGenericObjects _collection.SetMaxCount = GetMaxCount; } - public static bool operator +(AbstractCompany company, DrawningBus bus) + public static int operator +(AbstractCompany company, DrawningBus bus) { - return company._collection?.Insert(bus) ?? false; + return company._collection.Insert(bus); } - public static bool operator -(AbstractCompany company, int position) + public static DrawningBus? operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection.Remove(position); } public DrawningBus? GetRandomObject() diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs index 10b3762..bf04efc 100644 --- a/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -22,20 +22,20 @@ namespace AccordionBus.CollectionGenericObjects /// /// добавляемый объект /// - bool Insert(T obj); + int Insert(T obj); /// /// вставить по позиции /// /// добавляемый объект /// индекс /// - bool Insert(T obj, int position); + int Insert(T obj, int position); /// /// удаление /// /// индекс /// - bool Remove(int position); + T? Remove(int position); /// /// получение объекта по позиции /// diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs index 4caf5c1..0489942 100644 --- a/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -26,27 +26,27 @@ namespace AccordionBus.CollectionGenericObjects return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { for (int i = 0; i < _collection.Length; 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 >= _collection.Length) { return false; } + if (position < 0 || position >= _collection.Length) { return -1; } if (_collection[position] == null) { _collection[position] = obj; - return true; + return position; } else { @@ -55,7 +55,7 @@ namespace AccordionBus.CollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } @@ -64,19 +64,20 @@ namespace AccordionBus.CollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } } - return false; + return -1; } - public bool Remove(int position) + public T? Remove(int position) { - if (position < 0 || position >= _collection.Length) { return false;} + if (position < 0 || position >= _collection.Length) { return null;} + T? obj = _collection[position]; _collection[position] = null; - return true; + return obj; } } } diff --git a/AccordionBus/AccordionBus/FormBusCollection.cs b/AccordionBus/AccordionBus/FormBusCollection.cs index 4873e21..d9fb03a 100644 --- a/AccordionBus/AccordionBus/FormBusCollection.cs +++ b/AccordionBus/AccordionBus/FormBusCollection.cs @@ -55,7 +55,7 @@ namespace AccordionBus return; } - if (_company + _drawningBus) + if (_company + _drawningBus != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -89,7 +89,7 @@ namespace AccordionBus if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos) + if (_company - pos is DrawningBus) { MessageBox.Show("Объект удалён"); pictureBox.Image = _company.Show();