package Trolleybus; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; public class BusesGenericStorage { final HashMap> _busStorages; public List Keys() { if (_busStorages == null) { return null; } return _busStorages.keySet().stream().collect(Collectors.toList()); } private final int _pictureWidth; private final int _pictureHeight; public BusesGenericStorage(int pictureWidth, int pictureHeight) { _busStorages = new HashMap<>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } public void AddSet(String name) { // проверка, существует ли набор с таким ключём if (_busStorages.containsKey(name)) { return; } _busStorages.put(name, new BusesGenericCollection<>(_pictureWidth, _pictureHeight)); } public void DelSet(String name) { if (!_busStorages.containsKey(name)) { return; } _busStorages.remove(name); } //В Java нельзя перегружать операторы, в том числе индексаторы, поэтому ниже их замены public BusesGenericCollection Get(String name){ if (!_busStorages.containsKey(name)) { return null; } return _busStorages.get(name); } public DrawingBus Get(String nameOfCollection, int positionInCollection){ return _busStorages.get(nameOfCollection).Get(positionInCollection); } }