Работаем
This commit is contained in:
parent
289bcf43c7
commit
bf21edec3e
@ -1,4 +1,5 @@
|
||||
using ProjectElectricLocomotive.Drawnings;
|
||||
using ProjectElectricLocomotive.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -62,7 +63,7 @@ public abstract class AbstractCompany
|
||||
public static int operator +(AbstractCompany company, DrawningLocomotive locomotive)
|
||||
{
|
||||
|
||||
return company._collection.Insert(locomotive, new DrawiningLocomotiveEqutables()) ?? false;
|
||||
return company._collection?.Insert(locomotive, new DrawiningLocomotiveEqutables()) ?? throw new DrawningEqutablesException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
|
@ -60,6 +60,17 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
|
||||
// выброс ошибки если переполнение
|
||||
//выброс ошибки если такой объект уже есть в коллекции
|
||||
|
||||
if(comparer != null)
|
||||
{
|
||||
for(int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals(_collection[i], obj))
|
||||
{
|
||||
throw new CollectionDuplicateException(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
@ -73,6 +84,16 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
|
||||
// выброс ошибки, если переполнение
|
||||
// выброс ошибки если выход за границу
|
||||
//выброс ошибки если такой объект уже есть в коллекции
|
||||
if (comparer != null)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals(_collection[i], obj))
|
||||
{
|
||||
throw new CollectionDuplicateException(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
@ -106,7 +127,7 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
throw new NotImplementedException();
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,17 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
|
||||
//выброс ошибки, если выход за границы массива
|
||||
//выброс ошибки если такой объект уже есть в коллекции
|
||||
|
||||
if(comparer != null)
|
||||
{
|
||||
for(int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals(_collection[i], obj))
|
||||
{
|
||||
throw new CollectionDuplicateException(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
@ -84,6 +95,16 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
|
||||
//выброс ошибки, если выход за границы массива
|
||||
//выброс ошибки если такой объект уже есть в коллекции
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if(comparer != null)
|
||||
{
|
||||
for(int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals(_collection[i], obj))
|
||||
{
|
||||
throw new CollectionDuplicateException(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
@ -135,7 +156,7 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
throw new NotImplementedException();
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,20 +36,18 @@ where T : DrawningLocomotive
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
public void AddCollection(CollectionInfo collectionInfo)
|
||||
{
|
||||
if(collectionType != CollectionType.None && !_storages.ContainsKey(name)) {
|
||||
if(collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
}
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
}
|
||||
}
|
||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
// TODO Прописать логику для добавления
|
||||
// TODO Прописать логику для добавления
|
||||
if (_storages.ContainsKey(collectionInfo)) throw new CollectionExistsException(collectionInfo);
|
||||
if (collectionInfo.CollectionType == CollectionType.None)
|
||||
throw new CollectionNoTypeException("Пустой тип коллекции");
|
||||
if (collectionInfo.CollectionType == CollectionType.Massive)
|
||||
_storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||
else if (collectionInfo.CollectionType == CollectionType.List)
|
||||
_storages[collectionInfo] = new ListGenericObjects<T>();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ProjectElectricLocomotive.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@ -40,10 +41,24 @@ public class DrawiningLocomotiveEqutables : IEqualityComparer<DrawningLocomotive
|
||||
}
|
||||
if (x is DrawningElectricLocomotive && y is DrawningElectricLocomotive)
|
||||
{
|
||||
|
||||
|
||||
if(((EntityElectricLocomotive) x.EntityLocomotive).AdditionalColor != ((EntityElectricLocomotive)y.EntityLocomotive).AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((EntityElectricLocomotive)x.EntityLocomotive).Pantograph != ((EntityElectricLocomotive)y.EntityLocomotive).Pantograph)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((EntityElectricLocomotive)x.EntityLocomotive).BatteryStorage != ((EntityElectricLocomotive)y.EntityLocomotive).BatteryStorage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// TODO доделать логику сравнения дополнительных параметров
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -7,14 +7,39 @@ using System.Threading.Tasks;
|
||||
namespace ProjectElectricLocomotive.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Сравнение по цвету, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningLocomotiveCompareByColor : IComparer<DrawningLocomotive?>
|
||||
{
|
||||
public int Compare(DrawningLocomotive? x, DrawningLocomotive? y)
|
||||
{
|
||||
// TODO прописать логику сравения по цветам, скорости, весу
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
/// Сравнение по цвету, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningLocomotiveCompareByColor : IComparer<DrawningLocomotive?>
|
||||
{
|
||||
public int Compare(DrawningLocomotive? x, DrawningLocomotive? y)
|
||||
{
|
||||
if (x == null && y == null) return 0;
|
||||
if (x == null || x.EntityLocomotive == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityLocomotive == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ToHex(x.EntityLocomotive.BodyColor) != ToHex(y.EntityLocomotive.BodyColor))
|
||||
{
|
||||
return String.Compare(ToHex(x.EntityLocomotive.BodyColor), ToHex(y.EntityLocomotive.BodyColor),
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityLocomotive.Speed.CompareTo(y.EntityLocomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityLocomotive.Weight.CompareTo(y.EntityLocomotive.Weight);
|
||||
}
|
||||
|
||||
private static String ToHex(Color c) => $"#{c.R:X2}{c.G:X2}{c.B:X2}";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Exceptions
|
||||
{
|
||||
public class CollectionDuplicateException : Exception
|
||||
{
|
||||
public CollectionDuplicateException(object obj) : base("Объект " + obj + " не является уникальным") { }
|
||||
public CollectionDuplicateException() : base() { }
|
||||
public CollectionDuplicateException(string message) : base(message) { }
|
||||
public CollectionDuplicateException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected CollectionDuplicateException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectricLocomotive.Exceptions
|
||||
{
|
||||
public class DrawningEqutablesException : Exception
|
||||
{
|
||||
public DrawningEqutablesException() : base("Оба объекта прорисовки одинаковые") { }
|
||||
public DrawningEqutablesException(string message) : base(message) { }
|
||||
public DrawningEqutablesException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected DrawningEqutablesException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user