From 216d07bec8ccfcc37133e7b1af00010759930b77 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: Sat, 9 Mar 2024 14:58:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICollectionGenericObjects.cs | 46 +++++++++++ .../MassiveGenericObjects.cs | 82 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..10b3762 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus.CollectionGenericObjects +{ + public interface ICollectionGenericObjects + where T : class + { + /// + /// кол-во элем + /// + int Count { get; } + /// + /// установить макс элем + /// + int SetMaxCount { set; } + /// + /// вставить + /// + /// добавляемый объект + /// + bool Insert(T obj); + /// + /// вставить по позиции + /// + /// добавляемый объект + /// индекс + /// + bool Insert(T obj, int position); + /// + /// удаление + /// + /// индекс + /// + bool Remove(int position); + /// + /// получение объекта по позиции + /// + /// индекс + /// + T? Get(int position); + } +} diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..4caf5c1 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus.CollectionGenericObjects +{ + public class MassiveGenericObjects : ICollectionGenericObjects + where T : class + { + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + if (position < 0 || position >= _collection.Length) return null; + return _collection[position]; + } + + public bool Insert(T obj) + { + for (int i = 0; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + return false; + } + + public bool Insert(T obj, int position) + { + if (position < 0 || position >= _collection.Length) { return false; } + + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + else + { + for (int i = position + 1; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + + for (int i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + } + return false; + } + + public bool Remove(int position) + { + if (position < 0 || position >= _collection.Length) { return false;} + + _collection[position] = null; + return true; + } + } +}