PIbd-22_Chernyshev_G.J._29_.../Trolleybus/BusesGenericStorage.java
2023-12-01 19:42:28 +03:00

54 lines
1.7 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.

package Trolleybus;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class BusesGenericStorage {
final HashMap<String, BusesGenericCollection<DrawingBus, DrawingObjectBus>> _busStorages;
public List<String> 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<DrawingBus, DrawingObjectBus> 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);
}
}