PIbd-23_Mochalov_D.V._Locom.../MapsCollection.java

48 lines
2.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import java.util.ArrayList;
import java.util.HashMap;
public class MapsCollection {
/// Словарь (хранилище) с картами
final HashMap<String, MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>> _mapStorages;
/// Возвращение списка названий карт
public ArrayList<String> keys() {
return new ArrayList<String>(_mapStorages.keySet());
}
/// Ширина окна отрисовки
private final int _pictureWidth;
/// Высота окна отрисовки
private final int _pictureHeight;
/// Конструктор
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new HashMap<String, MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// Добавление карты
public void AddMap(String name, AbstractMap map)
{
// Логика для добавления
if (!_mapStorages.containsKey(name)) _mapStorages.put(name, new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
/// Удаление карты
public void DelMap(String name)
{
// Логика для удаления
if (_mapStorages.containsKey(name)) _mapStorages.remove(name);
}
/// Доступ к парковке
public MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> Get(String ind)
{
// Логика получения объекта
if (_mapStorages.containsKey(ind)) return _mapStorages.get(ind);
return null;
}
// Доп.индексатор из задания
public DrawningObjectLocomotive Get (String name, int position) {
if (_mapStorages.containsKey(name)) return _mapStorages.get(name)._setLocomotives.Get(position);
else return null;
}
}