Compare commits
No commits in common. "74c7268d4fefcf0e83a75dde4ffb854952a8f43c" and "92a8dc27f730b14fa006108b5f99b8cff784595d" have entirely different histories.
74c7268d4f
...
92a8dc27f7
@ -1,8 +1,11 @@
|
|||||||
using HoistingCrane.Drawning;
|
using System;
|
||||||
using HoistingCrane.Exceptions;
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Windows.Forms.VisualStyles;
|
||||||
|
|
||||||
namespace HoistingCrane.CollectionGenericObjects;
|
namespace HoistingCrane.CollectionGenericObjects;
|
||||||
|
|
||||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T> where T : class
|
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список объектов, которые храним
|
/// Список объектов, которые храним
|
||||||
@ -63,25 +66,39 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T> where T : clas
|
|||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public int Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= list.Count) throw new PositionOutOfCollectionException(position);
|
// Проверка, что не превышено максимальное количество элементов
|
||||||
T? temp = list[position];
|
if (Count == _maxCount)
|
||||||
list.RemoveAt(position);
|
{
|
||||||
return temp;
|
return -1;
|
||||||
|
}
|
||||||
|
// Проверка позиции
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
_collection.Insert(position, obj);
|
||||||
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<T?> GetItems()
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
// Проверка позиции
|
||||||
|
if (position >= Count || position < 0)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < list.Count; i++)
|
return null;
|
||||||
{
|
|
||||||
yield return list[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
T? obj = _collection[position];
|
||||||
|
_collection.RemoveAt(position);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
public void CollectionSort(IComparer<T> comparer)
|
public IEnumerable<T?> GetItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Count; ++i)
|
||||||
{
|
{
|
||||||
list.Sort(comparer);
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,15 +3,13 @@
|
|||||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
private T?[] arr;
|
/// <summary>
|
||||||
public MassivGenericObjects()
|
/// Массив объектов, которые храним
|
||||||
{
|
/// </summary>
|
||||||
arr = Array.Empty<T?>();
|
private T?[] _collection;
|
||||||
}
|
|
||||||
public int Count
|
public int Count => _collection.Length;
|
||||||
{
|
|
||||||
get { return arr.Length; }
|
|
||||||
}
|
|
||||||
public int MaxCount
|
public int MaxCount
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -33,52 +31,16 @@ 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 T? Remove(int position)
|
public CollectionType GetCollectionType => CollectionType.Massive;
|
||||||
{
|
|
||||||
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 IEnumerable<T?> GetItems()
|
/// <summary>
|
||||||
{
|
/// Конструктор
|
||||||
for (int i = 0; i < arr.Length; i++)
|
/// </summary>
|
||||||
{
|
public MassiveGenericObjects()
|
||||||
yield return arr[i];
|
{
|
||||||
=========
|
_collection = Array.Empty<T?>();
|
||||||
>>>>>>>>> Temporary merge branch 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void CollectionSort(IComparer<T> comparer)
|
|
||||||
{
|
|
||||||
T[] notNullArr = arr.OfType<T>().ToArray();
|
|
||||||
Array.Sort(notNullArr, comparer);
|
|
||||||
Array.Copy(notNullArr, 0, arr, 0, notNullArr.Length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
|
Loading…
Reference in New Issue
Block a user