файлы лабораторной

This commit is contained in:
Ivan_Starostin 2023-12-22 19:05:09 +04:00
parent c125641fc6
commit 8b2e357a8a
4 changed files with 139 additions and 0 deletions

View 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();
}
}
}

View 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);
}
}
}

View 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);
}
}
}

View 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;
}
}
}