что-то вечно, но ошибочно полагать, что это вечное останется с тобой навечно
This commit is contained in:
parent
793ecd010e
commit
86aee47092
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
internal class AirplaneCollectionInfo
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public AirplaneCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(AirplaneCollectionInfo? other)
|
||||
{
|
||||
if (other != null)
|
||||
{
|
||||
return Name == other.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||
using ProjectAirplaneWithRadar.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
internal class AirplaneCompareByColor : IComparer<DrawningAirplane?>
|
||||
{
|
||||
public int Compare(DrawningAirplane? x, DrawningAirplane? y)
|
||||
{
|
||||
if (x == null || x.EntityAirplane == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityAirplane == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
|
||||
if (x.EntityAirplane.BodyColor.Name != y.EntityAirplane.BodyColor.Name)
|
||||
{
|
||||
return x.EntityAirplane.BodyColor.Name.CompareTo(y.EntityAirplane.BodyColor.Name);
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
if (x is DrawningAirplane)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
if (x.GetType().Name == y.GetType().Name && x is DrawningAirplaneWithRadar)
|
||||
{
|
||||
EntityAirplaneWithRadar EntityX = (EntityAirplaneWithRadar)x.EntityAirplane;
|
||||
EntityAirplaneWithRadar EntityY = (EntityAirplaneWithRadar)y.EntityAirplane;
|
||||
if (EntityX.AdditionalColor.Name != EntityY.AdditionalColor.Name)
|
||||
{
|
||||
return EntityX.AdditionalColor.Name.CompareTo(EntityY.AdditionalColor.Name);
|
||||
}
|
||||
}
|
||||
var speedCompare = x.EntityAirplane.Speed.CompareTo(y.EntityAirplane.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
|
||||
return x.EntityAirplane.Weight.CompareTo(y.EntityAirplane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||
using ProjectAirplaneWithRadar.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
internal class AirplaneCompareByType : IComparer<DrawningAirplane?>
|
||||
{
|
||||
public int Compare(DrawningAirplane? x, DrawningAirplane? y)
|
||||
{
|
||||
if (x == null || x.EntityAirplane == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityAirplane == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityAirplane.Speed.CompareTo(y.EntityAirplane.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
|
||||
return x.EntityAirplane.Weight.CompareTo(y.EntityAirplane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
private readonly int _placeSizeWidth = 215;
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
public AirplanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
@ -28,7 +29,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Insert(obj)??false;
|
||||
return collect?._collection.Insert(obj, new DrawningAirplanesEqutables()) ?? false;
|
||||
}
|
||||
public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
|
@ -11,8 +11,8 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
internal class AirplanesGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, AirplanesGenericCollection<DrawningAirplane,DrawningObjectAirplane>> _airplanesStorages;
|
||||
public List<string> Keys => _airplanesStorages.Keys.ToList();
|
||||
readonly Dictionary<AirplaneCollectionInfo, AirplanesGenericCollection<DrawningAirplane,DrawningObjectAirplane>> _airplanesStorages;
|
||||
public List<AirplaneCollectionInfo> Keys => _airplanesStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
@ -20,7 +20,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
private static readonly char _separatorForObject = ':';
|
||||
public AirplanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_airplanesStorages = new Dictionary<string,AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>>();
|
||||
_airplanesStorages = new Dictionary<AirplaneCollectionInfo,AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -31,7 +31,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,
|
||||
foreach (KeyValuePair<AirplaneCollectionInfo,
|
||||
AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>> record in _airplanesStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
@ -39,7 +39,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
@ -98,7 +98,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_airplanesStorages.Add(record[0], collection);
|
||||
_airplanesStorages.Add(new AirplaneCollectionInfo (record[0], string.Empty), collection);
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
}
|
||||
@ -106,21 +106,22 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_airplanesStorages.Add(name, new AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>(_pictureWidth, _pictureHeight));
|
||||
_airplanesStorages.Add(new AirplaneCollectionInfo(name, string.Empty), new AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_airplanesStorages.ContainsKey(name))
|
||||
if (!_airplanesStorages.ContainsKey(new AirplaneCollectionInfo(name, string.Empty)))
|
||||
return;
|
||||
_airplanesStorages.Remove(name);
|
||||
_airplanesStorages.Remove(new AirplaneCollectionInfo(name, string.Empty));
|
||||
}
|
||||
public AirplanesGenericCollection<DrawningAirplane, DrawningObjectAirplane>?this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_airplanesStorages.ContainsKey(ind))
|
||||
return _airplanesStorages[ind];
|
||||
return null;
|
||||
AirplaneCollectionInfo indObj = new AirplaneCollectionInfo(ind, string.Empty);
|
||||
if (_airplanesStorages.ContainsKey(indObj))
|
||||
return _airplanesStorages[indObj];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||
using ProjectAirplaneWithRadar.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirplaneWithRadar.Generics
|
||||
{
|
||||
internal class DrawningAirplanesEqutables : IEqualityComparer<DrawningAirplane?>
|
||||
{
|
||||
public bool Equals(DrawningAirplane? x, DrawningAirplane? y)
|
||||
{
|
||||
if (x == null || x.EntityAirplane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityAirplane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityAirplane.Speed != y.EntityAirplane.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityAirplane.Weight != y.EntityAirplane.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityAirplane.BodyColor != y.EntityAirplane.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningAirplaneWithRadar && y is DrawningAirplaneWithRadar)
|
||||
{
|
||||
EntityAirplaneWithRadar EntityX = (EntityAirplaneWithRadar)x.EntityAirplane;
|
||||
EntityAirplaneWithRadar EntityY = (EntityAirplaneWithRadar)y.EntityAirplane;
|
||||
if (EntityX.Radar != EntityY.Radar)
|
||||
return false;
|
||||
if (EntityX.DopBak != EntityY.DopBak)
|
||||
return false;
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningAirplane obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@
|
||||
groupBoxAirplaneWithRadar.Dock = DockStyle.Right;
|
||||
groupBoxAirplaneWithRadar.Location = new Point(650, 28);
|
||||
groupBoxAirplaneWithRadar.Name = "groupBoxAirplaneWithRadar";
|
||||
groupBoxAirplaneWithRadar.Size = new Size(251, 464);
|
||||
groupBoxAirplaneWithRadar.Size = new Size(251, 522);
|
||||
groupBoxAirplaneWithRadar.TabIndex = 1;
|
||||
groupBoxAirplaneWithRadar.TabStop = false;
|
||||
groupBoxAirplaneWithRadar.Text = "Инструменты";
|
||||
@ -183,14 +183,14 @@
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(224, 26);
|
||||
SaveToolStripMenuItem.Size = new Size(166, 26);
|
||||
SaveToolStripMenuItem.Text = "Сохранить";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click_1;
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(224, 26);
|
||||
LoadToolStripMenuItem.Size = new Size(166, 26);
|
||||
LoadToolStripMenuItem.Text = "Загрузить";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
@ -202,7 +202,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(901, 492);
|
||||
ClientSize = new Size(901, 550);
|
||||
Controls.Add(groupBoxAirplaneWithRadar);
|
||||
Controls.Add(pictureBoxAirplanesCollection);
|
||||
Controls.Add(menuStrip1);
|
||||
|
@ -64,7 +64,7 @@ namespace ProjectAirplaneWithRadar
|
||||
Log.Information($"Äîáàâëåí îáúåêò â êîëëåêöèþ {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
||||
}
|
||||
catch(StorageOverflowException ex)
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
Log.Warning($"Êîëëåêöèÿ {listBoxStorages.SelectedItem.ToString() ?? string.Empty} ïåðåïîëíåíà");
|
||||
MessageBox.Show(ex.Message);
|
||||
@ -175,7 +175,7 @@ namespace ProjectAirplaneWithRadar
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning("Íå óäàëîñü ñîõðàíèòü");
|
||||
MessageBox.Show($"Íå ñîõðàíèëîñü: {ex.Message}","Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Íå ñîõðàíèëîñü: {ex.Message}", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,7 +198,7 @@ namespace ProjectAirplaneWithRadar
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning("Íå óäàëîñü çàãðóçèòü");
|
||||
MessageBox.Show($"Íå çàãðóçèëîñü: {ex.Message}","Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Íå çàãðóçèëîñü: {ex.Message}", "Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,19 +19,25 @@ namespace ProjectAirplaneWithRadar.Generics
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
public bool Insert(T airplane)
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
public bool Insert(T airplane, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(airplane, 0);
|
||||
Insert(airplane, 0, equal);
|
||||
return true;
|
||||
}
|
||||
public bool Insert(T airplane, int position)
|
||||
public bool Insert(T airplane, int position, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return false;
|
||||
if (equal != null)
|
||||
{
|
||||
if (_places.Contains(airplane, equal))
|
||||
throw new ArgumentException(nameof(airplane));
|
||||
}
|
||||
_places.Insert(position, airplane);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user