Compare commits
2 Commits
92a8dc27f7
...
74c7268d4f
Author | SHA1 | Date | |
---|---|---|---|
|
74c7268d4f | ||
|
bb32f6d69e |
@ -1,11 +1,8 @@
|
|||||||
using System;
|
using HoistingCrane.Drawning;
|
||||||
using System.CodeDom.Compiler;
|
using HoistingCrane.Exceptions;
|
||||||
using System.Windows.Forms.VisualStyles;
|
|
||||||
|
|
||||||
namespace HoistingCrane.CollectionGenericObjects;
|
namespace HoistingCrane.CollectionGenericObjects;
|
||||||
|
|
||||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
public class ListGenericObjects<T> : ICollectionGenericObjects<T> where T : class
|
||||||
where T : class
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список объектов, которые храним
|
/// Список объектов, которые храним
|
||||||
@ -66,39 +63,25 @@ where T : class
|
|||||||
return Count;
|
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)
|
public T? Remove(int position)
|
||||||
{
|
{
|
||||||
// Проверка позиции
|
if (position < 0 || position >= list.Count) throw new PositionOutOfCollectionException(position);
|
||||||
if (position >= Count || position < 0)
|
T? temp = list[position];
|
||||||
{
|
list.RemoveAt(position);
|
||||||
return null;
|
return temp;
|
||||||
}
|
|
||||||
T? obj = _collection[position];
|
|
||||||
_collection.RemoveAt(position);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<T?> GetItems()
|
public IEnumerable<T?> GetItems()
|
||||||
{
|
|
||||||
for (int i = 0; i < Count; ++i)
|
|
||||||
{
|
{
|
||||||
yield return _collection[i];
|
for(int i = 0; i < list.Count; i++)
|
||||||
|
{
|
||||||
|
yield return list[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CollectionSort(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
list.Sort(comparer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,13 +3,15 @@
|
|||||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
private T?[] arr;
|
||||||
/// Массив объектов, которые храним
|
public MassivGenericObjects()
|
||||||
/// </summary>
|
{
|
||||||
private T?[] _collection;
|
arr = Array.Empty<T?>();
|
||||||
|
}
|
||||||
public int Count => _collection.Length;
|
public int Count
|
||||||
|
{
|
||||||
|
get { return arr.Length; }
|
||||||
|
}
|
||||||
public int MaxCount
|
public int MaxCount
|
||||||
{
|
{
|
||||||
get
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
public IEnumerable<T?> GetItems()
|
||||||
/// Конструктор
|
{
|
||||||
/// </summary>
|
for (int i = 0; i < arr.Length; i++)
|
||||||
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)
|
||||||
|
@ -26,7 +26,7 @@ namespace HoistingCrane.Drawning
|
|||||||
if (trackedVehicle != null)
|
if (trackedVehicle != null)
|
||||||
{
|
{
|
||||||
return new DrawningHoistingCrane((EntityHoistingCrane)trackedVehicle);
|
return new DrawningHoistingCrane((EntityHoistingCrane)trackedVehicle);
|
||||||
}
|
}
|
||||||
trackedVehicle = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs);
|
trackedVehicle = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs);
|
||||||
if (trackedVehicle != null)
|
if (trackedVehicle != null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user