54 lines
1.7 KiB
Java
54 lines
1.7 KiB
Java
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);
|
||
}
|
||
} |