diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs index 80400f4..54b011d 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs @@ -1,11 +1,8 @@ -using System; -using System.CodeDom.Compiler; -using System.Windows.Forms.VisualStyles; - +using HoistingCrane.Drawning; +using HoistingCrane.Exceptions; namespace HoistingCrane.CollectionGenericObjects; -public class ListGenericObjects : ICollectionGenericObjects -where T : class +public class ListGenericObjects : ICollectionGenericObjects where T : class { /// /// Список объектов, которые храним @@ -66,39 +63,25 @@ where T : class return Count; } - public int Insert(T obj, int position) - { - // Проверка, что не превышено максимальное количество элементов - if (Count == _maxCount) - { - return -1; - } - // Проверка позиции - if (position >= Count || position < 0) - { - return -1; - } - _collection.Insert(position, obj); - return position; - } - public T? Remove(int position) { - // Проверка позиции - if (position >= Count || position < 0) - { - return null; - } - T? obj = _collection[position]; - _collection.RemoveAt(position); - return obj; + if (position < 0 || position >= list.Count) throw new PositionOutOfCollectionException(position); + T? temp = list[position]; + list.RemoveAt(position); + return temp; } - public IEnumerable GetItems() - { - for (int i = 0; i < Count; ++i) + public IEnumerable GetItems() { - yield return _collection[i]; + for(int i = 0; i < list.Count; i++) + { + yield return list[i]; + } + } + + public void CollectionSort(IComparer comparer) + { + list.Sort(comparer); } } } \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs index 29e6cc8..9680bbf 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs @@ -3,13 +3,15 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : class { - /// - /// Массив объектов, которые храним - /// - private T?[] _collection; - - public int Count => _collection.Length; - + private T?[] arr; + public MassivGenericObjects() + { + arr = Array.Empty(); + } + public int Count + { + get { return arr.Length; } + } public int MaxCount { get @@ -31,16 +33,52 @@ where T : class } } } - } + if (arr[i] == null) + { + arr[i] = obj; + return i; + } + } + } + } + throw new CollectionOverflowException(Count); + } + catch (PositionOutOfCollectionException ex) + { + MessageBox.Show(ex.Message); + return -1; + } + catch (ObjectIsPresentInTheCollectionException ex) + { + MessageBox.Show(ex.Message); + return -1; + } + } - public CollectionType GetCollectionType => CollectionType.Massive; + public T? Remove(int position) + { + if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position); + if (arr[position] == null) throw new ObjectNotFoundException(position); + T? temp = arr[position]; + arr[position] = null; + return temp; + } - /// - /// Конструктор - /// - public MassiveGenericObjects() - { - _collection = Array.Empty(); + public IEnumerable GetItems() + { + for (int i = 0; i < arr.Length; i++) + { + yield return arr[i]; +========= +>>>>>>>>> Temporary merge branch 2 + } + } + public void CollectionSort(IComparer comparer) + { + T[] notNullArr = arr.OfType().ToArray(); + Array.Sort(notNullArr, comparer); + Array.Copy(notNullArr, 0, arr, 0, notNullArr.Length); + } } public T? Get(int position) diff --git a/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs index ada1b71..2b9a11e 100644 --- a/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs +++ b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs @@ -26,7 +26,7 @@ namespace HoistingCrane.Drawning if (trackedVehicle != null) { return new DrawningHoistingCrane((EntityHoistingCrane)trackedVehicle); - } + } trackedVehicle = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs); if (trackedVehicle != null) {