исправления 7 лабораторной

This commit is contained in:
sardq 2023-12-28 09:44:41 +04:00
parent 0e7878555f
commit b45f27b91d

View File

@ -25,6 +25,7 @@ namespace HoistingCrane.Generics
if (Count >= _maxCount) if (Count >= _maxCount)
throw new StorageOverflowException(Count); throw new StorageOverflowException(Count);
_places.Insert(0, crane); _places.Insert(0, crane);
if (_places.Contains(null)) _places.Remove(null);
return 0; return 0;
} }
public int Insert(T crane, int position) public int Insert(T crane, int position)
@ -34,13 +35,15 @@ namespace HoistingCrane.Generics
if (Count >= _maxCount) if (Count >= _maxCount)
throw new StorageOverflowException(Count); throw new StorageOverflowException(Count);
_places.Insert(position, crane); _places.Insert(position, crane);
if(_places.Contains(null)) _places.Remove(null);
return position; return position;
} }
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
public bool Remove(int position) public bool Remove(int position)
{ {
if (_places[position] == null) if (position < 0 || position > _maxCount || position >= Count || _places[position] == null)
throw new CraneNotFoundException(position); throw new CraneNotFoundException(position);
if ((position < 0) || (position > _maxCount)) return false; if ((position < 0) || (position > _maxCount)) return false;
_places[position] = null; _places[position] = null;
return true; return true;
@ -56,7 +59,9 @@ namespace HoistingCrane.Generics
{ {
get get
{ {
if (position < 0 || position > _maxCount) if (position < 0 || position > Count)
return null;
if (_places.Count <= position)
return null; return null;
return _places[position]; return _places[position];
} }
@ -64,6 +69,8 @@ namespace HoistingCrane.Generics
{ {
if (position < 0 || position > _maxCount) if (position < 0 || position > _maxCount)
return; return;
if (_places.Count <= position)
return;
_places[position] = value; _places[position] = value;
} }
} }