Создание классов исключений. Обновление SetGeneric
This commit is contained in:
parent
5630e074f1
commit
fce83f96d5
17
ProjectBulldozer/Exceptions/BulldozerNotFoundException.cs
Normal file
17
ProjectBulldozer/Exceptions/BulldozerNotFoundException.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
namespace ProjectBulldozer.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class BulldozerNotFoundException : ApplicationException
|
||||||
|
{
|
||||||
|
public BulldozerNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
|
||||||
|
public BulldozerNotFoundException() : base() { }
|
||||||
|
|
||||||
|
public BulldozerNotFoundException(string message) : base(message) { }
|
||||||
|
|
||||||
|
public BulldozerNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
|
||||||
|
protected BulldozerNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
17
ProjectBulldozer/Exceptions/StorageOverflowException.cs
Normal file
17
ProjectBulldozer/Exceptions/StorageOverflowException.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
namespace ProjectBulldozer.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class StorageOverflowException : ApplicationException
|
||||||
|
{
|
||||||
|
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||||
|
|
||||||
|
public StorageOverflowException() : base() { }
|
||||||
|
|
||||||
|
public StorageOverflowException(string message) : base(message) { }
|
||||||
|
|
||||||
|
public StorageOverflowException(string message, Exception Exception) : base(message, Exception) { }
|
||||||
|
|
||||||
|
protected StorageOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
namespace ProjectBulldozer.Generics
|
using ProjectBulldozer.Exceptions;
|
||||||
|
namespace ProjectBulldozer.Generics
|
||||||
{
|
{
|
||||||
internal class SetGeneric<T> where T : class
|
internal class SetGeneric<T> where T : class
|
||||||
{
|
{
|
||||||
@ -12,24 +13,35 @@
|
|||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
public int Insert(T tract)
|
public bool Insert(T tract)
|
||||||
{
|
{
|
||||||
return Insert(tract, 0);
|
return Insert(tract, 0);
|
||||||
}
|
}
|
||||||
public int Insert(T tract, int position)
|
public bool Insert(T tract, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _maxCount) return -1;
|
if (position < 0 || position >= _maxCount)
|
||||||
|
{
|
||||||
|
throw new BulldozerNotFoundException(position);
|
||||||
|
}
|
||||||
|
if (Count >= _maxCount)
|
||||||
|
{
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
}
|
||||||
_places.Insert(position, tract);
|
_places.Insert(position, tract);
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
public T? Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0)
|
if (position < 0 || position >= _maxCount)
|
||||||
return null;
|
{
|
||||||
|
return false;
|
||||||
T? tmp = _places[position];
|
}
|
||||||
|
if (_places[position] == null)
|
||||||
|
{
|
||||||
|
throw new BulldozerNotFoundException(position);
|
||||||
|
}
|
||||||
_places[position] = null;
|
_places[position] = null;
|
||||||
return tmp;
|
return true;
|
||||||
}
|
}
|
||||||
public T? this[int position]
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user