2022-11-14 21:25:33 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace WinFormsApp1
|
|
|
|
|
{
|
|
|
|
|
internal class SetTraktorGeneric<T>
|
|
|
|
|
where T : class
|
|
|
|
|
{
|
2022-11-29 01:44:43 +04:00
|
|
|
|
private readonly List<T> _places;
|
|
|
|
|
public int Count => _places.Count;
|
|
|
|
|
private readonly int _maxCount;
|
2022-11-14 21:25:33 +04:00
|
|
|
|
private int TractorPlaces = 0;
|
|
|
|
|
|
|
|
|
|
public SetTraktorGeneric(int count)
|
|
|
|
|
{
|
2022-11-29 01:44:43 +04:00
|
|
|
|
_maxCount = count;
|
|
|
|
|
_places = new List<T>(); ;
|
2022-11-14 21:25:33 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Insert(T tractor)
|
|
|
|
|
{
|
|
|
|
|
return Insert(tractor, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Insert(T tractor, int position)
|
|
|
|
|
{
|
2022-11-29 01:44:43 +04:00
|
|
|
|
if (position < 0 && position > _maxCount)
|
2022-11-14 21:25:33 +04:00
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2022-11-29 01:44:43 +04:00
|
|
|
|
else
|
2022-11-14 21:25:33 +04:00
|
|
|
|
{
|
2022-11-29 01:44:43 +04:00
|
|
|
|
_places.Insert(position, tractor);
|
|
|
|
|
return position;
|
2022-11-14 21:25:33 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T Remove(int position)
|
|
|
|
|
{
|
2022-11-29 01:44:43 +04:00
|
|
|
|
if (position < 0 || position >= _maxCount)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var result = _places[position];
|
|
|
|
|
_places.RemoveAt(position);
|
|
|
|
|
return result;
|
2022-11-14 21:25:33 +04:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 01:44:43 +04:00
|
|
|
|
|
|
|
|
|
public T this[int position]
|
2022-11-14 21:25:33 +04:00
|
|
|
|
{
|
2022-11-29 01:44:43 +04:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (position >= 0 && position < _maxCount && position < Count)
|
|
|
|
|
{
|
|
|
|
|
return _places[position];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Insert(value, position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<T> GetBuses()
|
|
|
|
|
{
|
|
|
|
|
foreach (var traktor in _places)
|
|
|
|
|
{
|
|
|
|
|
if (traktor != null)
|
|
|
|
|
{
|
|
|
|
|
yield return traktor;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-14 21:25:33 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|