67 lines
2.1 KiB
Java
67 lines
2.1 KiB
Java
package ProjectElectricLocomotive;
|
|
|
|
import javax.xml.crypto.dsig.keyinfo.KeyValue;
|
|
import java.io.File;
|
|
import java.io.FileReader;
|
|
import java.io.FileWriter;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
public class LocomotivesGenericStorage {
|
|
|
|
public final char _separatorForKeyValue = '|';
|
|
public final char _separatorRecords = ';';
|
|
public final char _separatorForObject = ':';
|
|
final HashMap<String, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> _locomotiveStorage;
|
|
|
|
public List<String> Keys() {
|
|
return _locomotiveStorage.keySet().stream().toList();
|
|
}
|
|
|
|
private final int _pictureWidth;
|
|
private final int _pictureHeight;
|
|
|
|
public LocomotivesGenericStorage(int pictureWidth, int pictureHeight) {
|
|
_locomotiveStorage = new HashMap<>();
|
|
_pictureWidth = pictureWidth;
|
|
_pictureHeight = pictureHeight;
|
|
}
|
|
|
|
public void AddSet(String name) {
|
|
if (!(_locomotiveStorage.containsKey(name))) {
|
|
_locomotiveStorage.put(name, new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(_pictureWidth, _pictureHeight));
|
|
}
|
|
}
|
|
|
|
public void DelSet(String name) {
|
|
if (_locomotiveStorage.keySet().contains(name)) {
|
|
_locomotiveStorage.remove(name);
|
|
}
|
|
}
|
|
|
|
public LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> get(String ind) {
|
|
if (_locomotiveStorage.keySet().contains(ind)) {
|
|
return _locomotiveStorage.get(ind);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public DrawingObjectLocomotive get(String name, int ind) {
|
|
if (_locomotiveStorage.keySet().contains(ind)) {
|
|
return _locomotiveStorage.get(name).GetU(ind);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public boolean SaveData(String filename) {
|
|
if (new File(filename).exists()) {
|
|
new File(filename).delete();
|
|
}
|
|
StringBuilder data = new StringBuilder();
|
|
// for(KeyValue<String, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> record : _locomotiveStorage)
|
|
|
|
|
|
return true;
|
|
}
|
|
}
|