PIbd-21_Kouvshinoff_T._A._W.../laba1Loco/TrainsGenericStorage.java
2023-11-05 01:47:52 +04:00

73 lines
2.4 KiB
Java

package laba1Loco;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class TrainsGenericStorage {
/// <summary>
/// Словарь (хранилище)
/// </summary>
HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> _trainStorages;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<String> Keys(){return _trainStorages.keySet().stream().collect(Collectors.toList());}
/// <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)
{
_trainStorages = new HashMap<String, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление набора
/// </summary>
/// <param name="name">Название набора</param>
public void AddSet(String name)
{
if (_trainStorages.containsKey(name))
return;
_trainStorages.put(name, new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight));
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="name">Название набора</param>
public void DelSet(String name)
{
if (!_trainStorages.containsKey(name))
return;
_trainStorages.remove(name);
}
/// <summary>
/// Доступ к набору
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> get(String ind)
{
if (_trainStorages.containsKey(ind))
return _trainStorages.get(ind);
return null;
}
public DrawningObjectTrain get(String ind1, int ind2){
if (!_trainStorages.containsKey(ind1))
return null;
return _trainStorages.get(ind1).GetU(ind2);
}
}