comparer & sorting
This commit is contained in:
parent
9c904ea947
commit
7fc6a50c1b
@ -31,12 +31,11 @@ public abstract class AbstractCompany
|
|||||||
|
|
||||||
// Перегрузка оператора сложения для класса
|
// Перегрузка оператора сложения для класса
|
||||||
public static int operator +(AbstractCompany company,
|
public static int operator +(AbstractCompany company,
|
||||||
DrawningBase trasport) =>
|
DrawningBase transport) => company._collection.Insert(transport, new DrawiningShipEqutables());
|
||||||
company._collection.Insert(trasport, new DrawiningShipEqutables());
|
|
||||||
|
|
||||||
// Перегрузка оператора удаления для класса
|
// Перегрузка оператора удаления для класса
|
||||||
public static DrawningBase operator -(AbstractCompany company,
|
public static DrawningBase operator -(AbstractCompany company,
|
||||||
int pos) => company._collection.Remove(pos);
|
int pos) => company._collection?.Remove(pos);
|
||||||
|
|
||||||
// Сортировка ----------------------------------------------------------- [!]
|
// Сортировка ----------------------------------------------------------- [!]
|
||||||
public void Sort(IComparer<DrawningBase?> comparer) =>
|
public void Sort(IComparer<DrawningBase?> comparer) =>
|
||||||
|
@ -139,7 +139,7 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CollectionSort(IComparer<T> comparer)
|
void ICollectionGenObj<T>.CollectionSort(IComparer<T?> comparer)
|
||||||
{
|
{
|
||||||
Array.Sort(_collection, comparer);
|
Array.Sort(_collection, comparer);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ public class ListGenObj<T> : ICollectionGenObj<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CollectionSort(IComparer<T> comparer)
|
void ICollectionGenObj<T>.CollectionSort(IComparer<T?> comparer)
|
||||||
{
|
{
|
||||||
_collection.Sort(comparer);
|
_collection.Sort(comparer);
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,18 @@ public class DrawningShipCompare : IComparer<DrawningBase?>
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y == null || y.EntityTransport == null)
|
if (y == null || y.EntityTransport == null)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x.GetType().Name != y.GetType().Name)
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
{
|
{
|
||||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var speedCompare = x.EntityTransport.Speed.CompareTo(y.EntityTransport.Speed);
|
var speedCompare = x.EntityTransport.Speed.CompareTo(y.EntityTransport.Speed);
|
||||||
|
|
||||||
if (speedCompare != 0)
|
if (speedCompare != 0)
|
||||||
{
|
{
|
||||||
return speedCompare;
|
return speedCompare;
|
||||||
|
@ -11,28 +11,30 @@ public class DrawiningShipEqutables : IEqualityComparer<DrawningBase?>
|
|||||||
if (x == null || x.EntityTransport == null) return false;
|
if (x == null || x.EntityTransport == null) return false;
|
||||||
if (y == null || y.EntityTransport == null) return false;
|
if (y == null || y.EntityTransport == null) return false;
|
||||||
if (x.GetType().Name != y.GetType().Name) return false;
|
if (x.GetType().Name != y.GetType().Name) return false;
|
||||||
|
|
||||||
if (x.EntityTransport.Speed != y.EntityTransport.Speed) return false;
|
if (x.EntityTransport.Speed != y.EntityTransport.Speed) return false;
|
||||||
if (x.EntityTransport.Weight != y.EntityTransport.Weight) return false;
|
if (x.EntityTransport.Weight != y.EntityTransport.Weight) return false;
|
||||||
if (x.EntityTransport.MainColor != y.EntityTransport.MainColor) return false;
|
if (x.EntityTransport.MainColor != y.EntityTransport.MainColor) return false;
|
||||||
|
|
||||||
if (x is DrawningCruiser && y is DrawningCruiser)
|
if (x is DrawningCruiser && y is DrawningCruiser)
|
||||||
{
|
{
|
||||||
/*
|
/* public Color AdditionalColor { get; private set; } // доп. цвет
|
||||||
public Color AdditionalColor { get; private set; } // доп. цвет
|
|
||||||
// признаки (наличия)
|
// признаки (наличия)
|
||||||
public bool HelicopterPads { get; private set; } // вертолетная площадка
|
public bool HelicopterPads { get; private set; } // вертолетная площадка
|
||||||
public bool Hangars { get; private set; } // ангар
|
public bool Hangars { get; private set; } // ангар */
|
||||||
*/
|
|
||||||
if (((EntityCruiser)x.EntityTransport).AdditionalColor
|
|
||||||
!= ((EntityCruiser)y.EntityTransport).AdditionalColor) return false;
|
|
||||||
|
|
||||||
if (((EntityCruiser)x.EntityTransport).HelicopterPads
|
EntityCruiser EntityX = (EntityCruiser)x.EntityTransport;
|
||||||
!= ((EntityCruiser)y.EntityTransport).HelicopterPads) return false;
|
EntityCruiser EntityY = (EntityCruiser)y.EntityTransport;
|
||||||
|
|
||||||
if (((EntityCruiser)x.EntityTransport).Hangars
|
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||||
!= ((EntityCruiser)y.EntityTransport).Hangars) return false;
|
return false;
|
||||||
|
|
||||||
|
if (EntityX.Hangars != EntityY.Hangars)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (EntityX.HelicopterPads != EntityY.HelicopterPads)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public int GetHashCode([DisallowNull] DrawningBase obj)
|
public int GetHashCode([DisallowNull] DrawningBase obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user