PIbd-21_Kouvshinoff_T._A._W.../laba1Loco/TrainsGenericStorage.java

73 lines
2.4 KiB
Java
Raw Normal View History

2023-10-24 02:19:14 +04:00
package laba1Loco;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class TrainsGenericStorage {
/// <summary>
/// Словарь (хранилище)
/// </summary>
2023-11-05 01:47:52 +04:00
HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> _trainStorages;
2023-10-24 02:19:14 +04:00
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
2023-11-05 01:47:52 +04:00
public List<String> Keys(){return _trainStorages.keySet().stream().collect(Collectors.toList());}
2023-10-24 02:19:14 +04:00
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public TrainsGenericStorage(int pictureWidth, int pictureHeight)
{
2023-11-05 01:47:52 +04:00
_trainStorages = new HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>>();
2023-10-24 02:19:14 +04:00
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление набора
/// </summary>
/// <param name="name">Название набора</param>
public void AddSet(String name)
{
2023-11-05 01:47:52 +04:00
if (_trainStorages.containsKey(name))
2023-10-24 02:19:14 +04:00
return;
2023-11-05 01:47:52 +04:00
_trainStorages.put(name, new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight));
2023-10-24 02:19:14 +04:00
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="name">Название набора</param>
public void DelSet(String name)
{
2023-11-05 01:47:52 +04:00
if (!_trainStorages.containsKey(name))
2023-10-24 02:19:14 +04:00
return;
2023-11-05 01:47:52 +04:00
_trainStorages.remove(name);
2023-10-24 02:19:14 +04:00
}
/// <summary>
/// Доступ к набору
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> get(String ind)
{
2023-11-05 01:47:52 +04:00
if (_trainStorages.containsKey(ind))
return _trainStorages.get(ind);
2023-10-24 02:19:14 +04:00
return null;
}
2023-11-05 01:47:52 +04:00
public DrawningObjectTrain get(String ind1, int ind2){
if (!_trainStorages.containsKey(ind1))
return null;
return _trainStorages.get(ind1).GetU(ind2);
}
2023-10-24 02:19:14 +04:00
}