lab8 fix
This commit is contained in:
parent
48e39e9f2c
commit
5862585572
@ -127,10 +127,17 @@ namespace Bulldozer
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBulldozers();
|
||||
} catch(Exception ex) {
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Объект не добавлен в набор {listBoxBulldozerStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show("Добавляемый объект уже сущесвует в коллекции");
|
||||
_logger.LogWarning($"Добавляемый объект уже существует в коллекции {listBoxBulldozerStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
33
Bulldozer/Bulldozer/Generics/BulldozerCollectionInfo.cs
Normal file
33
Bulldozer/Bulldozer/Generics/BulldozerCollectionInfo.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bulldozer.Generics
|
||||
{
|
||||
internal class BulldozerCollectionInfo: IEquatable<BulldozerCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public BulldozerCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(BulldozerCollectionInfo other)
|
||||
{
|
||||
if (Name != other?.Name)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ namespace Bulldozer.Generics
|
||||
{
|
||||
if (obj == null)
|
||||
return false;
|
||||
return collect._collection.Insert(obj);
|
||||
return collect?._collection.Insert(obj, new DrawingBulldozerEqutables()) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -3,6 +3,7 @@ using Bulldozer.MovementStrategy;
|
||||
using System.Text;
|
||||
using Bulldozer.Exceptions;
|
||||
using System.Numerics;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Bulldozer.Generics
|
||||
{
|
||||
@ -14,11 +15,11 @@ namespace Bulldozer.Generics
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> _bulldozerStorages;
|
||||
readonly Dictionary<BulldozerCollectionInfo, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> _bulldozerStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _bulldozerStorages.Keys.ToList();
|
||||
public List<BulldozerCollectionInfo> Keys => _bulldozerStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -34,7 +35,7 @@ namespace Bulldozer.Generics
|
||||
/// <param name="pictureHeight"></param>
|
||||
public BulldozersGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_bulldozerStorages = new Dictionary<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>>();
|
||||
_bulldozerStorages = new Dictionary<BulldozerCollectionInfo, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -44,9 +45,9 @@ namespace Bulldozer.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (!_bulldozerStorages.ContainsKey(name))
|
||||
if (!_bulldozerStorages.ContainsKey(new BulldozerCollectionInfo(name, string.Empty)))
|
||||
{
|
||||
_bulldozerStorages.Add(name, new BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>(_pictureWidth, _pictureHeight));
|
||||
_bulldozerStorages.Add(new BulldozerCollectionInfo(name, string.Empty), new BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
}
|
||||
@ -58,9 +59,9 @@ namespace Bulldozer.Generics
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO: Прописать логику для удаления набора
|
||||
if (_bulldozerStorages.ContainsKey(name))
|
||||
if (_bulldozerStorages.ContainsKey(new BulldozerCollectionInfo(name, string.Empty)))
|
||||
{
|
||||
_bulldozerStorages.Remove(name);
|
||||
_bulldozerStorages.Remove(new BulldozerCollectionInfo(name, string.Empty));
|
||||
}
|
||||
|
||||
}
|
||||
@ -73,14 +74,11 @@ namespace Bulldozer.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bulldozerStorages.ContainsKey(ind))
|
||||
if (_bulldozerStorages.ContainsKey(new BulldozerCollectionInfo(ind, string.Empty)))
|
||||
{
|
||||
return _bulldozerStorages[ind];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
return _bulldozerStorages[new BulldozerCollectionInfo(ind, string.Empty)];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
@ -107,7 +105,7 @@ namespace Bulldozer.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> record in _bulldozerStorages)
|
||||
foreach (KeyValuePair<BulldozerCollectionInfo, BulldozersGenericCollection<DrawingBulldozer, DrawingObjectBulldozer>> record in _bulldozerStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingBulldozer? elem in record.Value.GetBulldozers)
|
||||
@ -189,7 +187,7 @@ namespace Bulldozer.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_bulldozerStorages.Add(record[0], collection);
|
||||
_bulldozerStorages.Add(new BulldozerCollectionInfo(record[0], string.Empty), collection);
|
||||
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
|
@ -45,7 +45,10 @@ namespace Bulldozer.Generics
|
||||
/// <returns></returns>
|
||||
public bool Insert(T bulldozer, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
return Insert(bulldozer, 0, equal);
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(bulldozer, 0, equal);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -55,10 +58,14 @@ namespace Bulldozer.Generics
|
||||
/// <returns></returns>
|
||||
public bool Insert(T bulldozer , int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount) {
|
||||
throw new StorageOverflowException("Вставка невозможна.");
|
||||
if (_places.Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (Count >= _maxCount) throw new StorageOverflowException(_maxCount);
|
||||
|
||||
if (equal != null)
|
||||
{
|
||||
if (_places.Contains(bulldozer, equal))
|
||||
|
Loading…
Reference in New Issue
Block a user