Лабораторная работа №3 (убраны TODO)

This commit is contained in:
DjonniStorm 2024-03-26 23:42:52 +04:00
parent cdbe8f783e
commit db190a81b7
3 changed files with 7 additions and 13 deletions

View File

@ -1,6 +1,4 @@
using ProjectCleaningCar.Drawning; using ProjectCleaningCar.Drawning;
using ProjectCleaningCar.Entities;
using System.Drawing;
namespace ProjectCleaningCar.CollectionGenericObjects; namespace ProjectCleaningCar.CollectionGenericObjects;
/// <summary> /// <summary>

View File

@ -1,5 +1,8 @@
namespace ProjectCleaningCar.CollectionGenericObjects; namespace ProjectCleaningCar.CollectionGenericObjects;
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class where T : class
{ {
@ -25,13 +28,15 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
} }
} }
} }
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects() public MassiveGenericObjects()
{ {
_collection = Array.Empty<T?>(); _collection = Array.Empty<T?>();
} }
public T? Get(int position) public T? Get(int position)
{ {
// TODO проверка позиции
if (position < 0 || position >= Count) return null; if (position < 0 || position >= Count) return null;
return _collection[position]; return _collection[position];
} }
@ -45,16 +50,10 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
return i; return i;
} }
} }
// TODO вставка в свободное место набора
return -1; return -1;
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
if (position >= Count || position < 0) return -1; if (position >= Count || position < 0) return -1;
if (_collection[position] == null) if (_collection[position] == null)
{ {
@ -85,8 +84,6 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
} }
public T? Remove(int position) public T? Remove(int position)
{ {
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= Count || position < 0) return null; if (position >= Count || position < 0) return null;
T? myObject = _collection[position]; T? myObject = _collection[position];
_collection[position] = null; _collection[position] = null;

View File

@ -64,7 +64,6 @@ public partial class FormCleaningCarCollection : Form
random.Next(1000, 3000), GetColor(random)); random.Next(1000, 3000), GetColor(random));
break; break;
case nameof(DrawningCleaningCar): case nameof(DrawningCleaningCar):
// TODO вызов диалогового окна для выбора цвета
drawningTruck = new DrawningCleaningCar(random.Next(100, 300), random.Next(1000, 3000), drawningTruck = new DrawningCleaningCar(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random), GetColor(random), GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),