ISEbd-12 Rozhkov.I.E. LabWork08 Simple #8
@ -8,9 +8,9 @@ public interface ICollectionGenericObjects<T>
|
||||
|
||||
int MaxCount { get; set; }
|
||||
|
||||
int Insert(T obj, IEqualityComparer<DrawningShip?>? comparer = null);
|
||||
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
int Insert(T obj, int position, IEqualityComparer<DrawningShip?>? comparer = null);
|
||||
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
T? Remove(int position);
|
||||
|
||||
|
@ -32,50 +32,45 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj, IEqualityComparer<DrawningShip?>? comparer = null)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если переполнение
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
}
|
||||
}
|
||||
|
||||
_collection.Add(obj);
|
||||
return _collection.Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position, IEqualityComparer<DrawningShip?>? comparer = null)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы списка
|
||||
// TODO выброс ошибки, если переполнение
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
}
|
||||
}
|
||||
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
}
|
||||
|
@ -53,18 +53,21 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj, IEqualityComparer<DrawningShip?>? comparer = null)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
// TODO выброс ошибки, если переполнение
|
||||
for (int i = 0; i < Count; i++)
|
||||
if (comparer != null)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
if ((comparer as IEqualityComparer<DrawningShip>).Equals(obj as DrawningShip, item as DrawningShip))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
@ -77,24 +80,26 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position, IEqualityComparer<DrawningShip?>? comparer = null)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы массива
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
// TODO выброс ошибки, если переполнение
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningShip>).Equals(obj as DrawningShip, item as DrawningShip))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
|
12
ProjectPlane/ProjectPlane/log20240520.txt
Normal file
12
ProjectPlane/ProjectPlane/log20240520.txt
Normal file
@ -0,0 +1,12 @@
|
||||
2024-05-20 13:25:42.8162 | INFORMATION | ProjectPlane.FormShipCollection | Добавлена коллекция: edhh типа: Massive
|
||||
2024-05-20 13:25:50.1068 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Blue
|
||||
2024-05-20 13:25:54.2419 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Red
|
||||
2024-05-20 13:26:02.3952 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Blue:Red:True:True
|
||||
2024-05-20 13:26:19.6205 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Purple
|
||||
2024-05-20 13:26:34.6992 | INFORMATION | ProjectPlane.FormShipCollection | Добавлена коллекция: eha blya типа: List
|
||||
2024-05-20 13:26:47.2484 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Black:Black:True:True
|
||||
2024-05-20 13:27:00.5461 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Black:White:True:True
|
||||
2024-05-20 13:28:19.2272 | INFORMATION | ProjectPlane.FormShipCollection | Удален объект по позиции 1
|
||||
2024-05-20 13:28:39.0064 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Red:Purple:True:True
|
||||
2024-05-20 13:28:46.8157 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Red
|
||||
2024-05-20 13:29:12.9298 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Black
|
Loading…
Reference in New Issue
Block a user