файлы лабораторной
This commit is contained in:
parent
c125641fc6
commit
8b2e357a8a
56
lainer/Lainer1/DrawingLainerEqutables.cs
Normal file
56
lainer/Lainer1/DrawingLainerEqutables.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using ProjectLainer.DrawningObjects;
|
||||
using ProjectLainer.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
namespace ProjectLainer.Generics
|
||||
{
|
||||
internal class DrawiningLainerEqutables : IEqualityComparer<DrawingEntity?>
|
||||
{
|
||||
public bool Equals(DrawingEntity? x, DrawingEntity? y)
|
||||
{
|
||||
if (x == null || x.EntityLainer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityLainer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityLainer.Speed != y.EntityLainer.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityLainer.Weight != y.EntityLainer.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityLainer.BodyColor != y.EntityLainer.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningSuperLainer && y is DrawningSuperLainer)
|
||||
{
|
||||
EntitySuperLainer entityX = (EntitySuperLainer)x.EntityLainer;
|
||||
EntitySuperLainer entityY = (EntitySuperLainer)y.EntityLainer;
|
||||
if(entityX.Pools != entityY.Pools)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(entityX.Decks != entityY.Decks)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(entityX.AdditionalColor != entityY.AdditionalColor) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawingEntity obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
lainer/Lainer1/LainerCompareByColor.cs
Normal file
34
lainer/Lainer1/LainerCompareByColor.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using ProjectLainer.DrawningObjects;
|
||||
using ProjectLainer.Entities;
|
||||
|
||||
namespace ProjectLainer.Generics
|
||||
{
|
||||
internal class LainerCompareByColor : IComparer<DrawingEntity?>
|
||||
{
|
||||
public int Compare(DrawingEntity? x, DrawingEntity? y)
|
||||
{
|
||||
if (x == null || x.EntityLainer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityLainer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
//по цвету
|
||||
var colorCompare = x.EntityLainer.BodyColor.Name.CompareTo(y.EntityLainer.BodyColor.Name);
|
||||
if(colorCompare != 0)
|
||||
{
|
||||
return colorCompare;
|
||||
}
|
||||
//по скорости
|
||||
var speedCompare = x.EntityLainer.Speed.CompareTo(y.EntityLainer.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
//по весу
|
||||
return x.EntityLainer.Weight.CompareTo(y.EntityLainer.Weight);
|
||||
}
|
||||
}
|
||||
}
|
28
lainer/Lainer1/LainerCompareByType.cs
Normal file
28
lainer/Lainer1/LainerCompareByType.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using ProjectLainer.DrawningObjects;
|
||||
namespace ProjectLainer.Generics
|
||||
{
|
||||
internal class LainerCompareByType : IComparer<DrawingEntity?>
|
||||
{
|
||||
public int Compare(DrawingEntity? x, DrawingEntity? y)
|
||||
{
|
||||
if (x == null || x.EntityLainer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityLainer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityLainer.Speed.CompareTo(y.EntityLainer.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityLainer.Weight.CompareTo(y.EntityLainer.Weight);
|
||||
}
|
||||
}
|
||||
}
|
21
lainer/Lainer1/LainersCollectionInfo.cs
Normal file
21
lainer/Lainer1/LainersCollectionInfo.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace ProjectLainer.Generics
|
||||
{
|
||||
internal class LainersCollectionInfo : IEquatable<LainersCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public LainersCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(LainersCollectionInfo? other)
|
||||
{
|
||||
if(other!= null)
|
||||
{
|
||||
return this.Name == other.Name;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user