8 лаба не готовая
This commit is contained in:
parent
484c309603
commit
81924c5d00
@ -58,9 +58,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="car">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningBus bus)
|
||||
public static bool operator +(AbstractCompany company, DrawningBus bus)
|
||||
{
|
||||
return company._collection?.Insert(bus) ?? -1;
|
||||
return company._collection?.Insert(bus, new DrawiningBusEqutables()) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -71,7 +71,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static DrawningBus operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? null;
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -102,14 +102,15 @@ public abstract class AbstractCompany
|
||||
DrawningBus? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
catch (ObjectNotFoundException e)
|
||||
{ }
|
||||
catch (PositionOutOfCollectionException e)
|
||||
{ }
|
||||
catch (Exception e) { }
|
||||
|
||||
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
public void Sort(IComparer<DrawningBus?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ProjectAirbus.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -12,13 +13,14 @@ public interface ICollectionGenericObjects<T>
|
||||
{
|
||||
int Count { get; }
|
||||
int MaxCount{get;set;}
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, int position);
|
||||
T Remove(int position);
|
||||
int Insert(T obj, IEqualityComparer<DrawningBus?>? comparer = null );
|
||||
int Insert(T obj, int position, IEqualityComparer<DrawningBus?>? comparer = null);
|
||||
T? Remove(int position);
|
||||
T? Get(int position);
|
||||
|
||||
CollectionType GetCollectionType { get; }
|
||||
|
||||
IEnumerable<T> GetItems();
|
||||
void CollectionSort(IComparer<T> comparer);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
using ProjectAirbus.CollectionGenericObjects;
|
||||
using ProjectAirbus.Drawnings;
|
||||
using ProjectAirbus.Exceptions;
|
||||
using System.Linq;
|
||||
|
||||
namespace ProjectAirBus.CollectionGenericObjects;
|
||||
|
||||
@ -18,11 +20,11 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
/// <summary>
|
||||
/// Максимально допустимое число объектов в списке
|
||||
/// </summary>
|
||||
private int _maxCount = 10;
|
||||
private int _maxCount;
|
||||
|
||||
public int Count => _collection.Count;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.List;
|
||||
|
||||
@ -43,25 +45,41 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<DrawningBus?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки если переполнение
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<DrawningBus?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки если переполнение
|
||||
// TODO выброс ошибки если за границу
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
public T Remove(int position)
|
||||
{
|
||||
|
||||
// TODO если выброс за границу
|
||||
@ -77,4 +95,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectAirbus.Exceptions;
|
||||
using ProjectAirbus.Drawnings;
|
||||
using ProjectAirbus.Exceptions;
|
||||
|
||||
namespace ProjectAirbus.CollectionGenericObjects;
|
||||
|
||||
@ -55,9 +56,18 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<DrawningBus?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки если переполнение
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawingBus>).Equals(obj as DrawingBus, item as DrawingBus))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
@ -66,17 +76,25 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
index++;
|
||||
}
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<DrawningBus?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки если переполнение
|
||||
// TODO выброс ошибки если выход за границу
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawingBus>).Equals(obj as DrawingBus, item as DrawingBus))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null)
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
@ -89,7 +107,7 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
index++;
|
||||
}
|
||||
index = position - 1;
|
||||
while (index >= 0)
|
||||
@ -99,9 +117,10 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
--index;
|
||||
index--;
|
||||
}
|
||||
throw new CollectionOverflowException(Count);
|
||||
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
@ -121,6 +140,11 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirbus.Drawnings;
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawiningBusEqutables : IEqualityComparer<DrawningBus?>
|
||||
{
|
||||
public bool Equals(DrawningBus? x, DrawningBus? y)
|
||||
{
|
||||
if (x == null || x.EntityBus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y.EntityBus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBus.Speed != y.EntityBus.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBus.Weight != y.EntityBus.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBus.BodyColor != y.EntityBus.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningAirbus && y is DrawningAirbus)
|
||||
{
|
||||
// TODO доделать логику сравнения дополнительных параметров
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningBus obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirbus.Drawnings;
|
||||
|
||||
public class DrawningBusCompareByColor : IComparer<DrawningBus?>
|
||||
{
|
||||
public int Compare(DrawningBus? x, DrawningBus? y)
|
||||
{
|
||||
// TODO прописать логику сравения по цветам, скорости, весу
|
||||
if (x == null || x.EntityBus == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityBus == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodycolorCompare = x.EntityBus.BodyColor.Name.CompareTo(y.EntityBus.BodyColor.Name);
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
var speedCompare = x.EntityBus.Speed.CompareTo(y.EntityBus.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityBus.Weight.CompareTo(y.EntityBus.Weight);
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirbus.Drawnings;
|
||||
|
||||
internal class DrawningBusCompareByType : IComparer<DrawningBus?>
|
||||
{
|
||||
public int Compare(DrawningBus? x, DrawningBus? y)
|
||||
{
|
||||
if (x == null || x.EntityBus == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (y == null || y.EntityBus == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityBus.Speed.CompareTo(y.EntityBus.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityBus.Weight.CompareTo(y.EntityBus.Weight);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user