diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ExtensionBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ExtensionBus.java index 7154de6..263eabe 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ExtensionBus.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ExtensionBus.java @@ -51,7 +51,7 @@ public class ExtensionBus { public static String GetDataForSave(DrawingBus drawingBus) { var bus = drawingBus.Bus; - var str = String.format("%d:%f:%s:%d:%s", drawingBus._speed, drawingBus._weight, drawingBus._bodyColor.toString(), + var str = String.format("%d:%f:%s:%d:%s", bus.Speed, bus.Weight, bus.BodyColor.toString(), drawingBus._countOfDoors, CreateDoors(drawingBus.Doors));; if (!(bus instanceof EntityDDB ddb)) { diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java index fc95811..604480a 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java @@ -171,7 +171,10 @@ public class MapWithSetBusesGeneric> _mapStorages; @@ -86,6 +85,13 @@ public class MapsCollection { return true; } + static String[] reverse(String myArray[]) + { + Collections.reverse(Arrays.asList(myArray)); + return (String[]) Arrays.stream(myArray).toArray(); + } + + public boolean SaveStorage(String filename, String key) throws IOException { Files.deleteIfExists(Paths.get(filename)); @@ -95,11 +101,15 @@ public class MapsCollection { { writer.write("MapsCollectionStorage" + System.lineSeparator()); MapWithSetBusesGeneric storage = _mapStorages.get(key); + if (storage == null) { + return false; + } String[] data = storage.GetData(separatorDict, separatorData).split("\\|"); writer.write(key + ":" + data[0] + System.lineSeparator()); - for (var bus : data[1].split(";")) { - writer.write(bus); + var buses = data[1].split(";"); + for (int i = buses.length - 1; i >= 0; i--) { + writer.write(buses[i]); writer.write(System.lineSeparator()); } @@ -123,7 +133,6 @@ public class MapsCollection { return false; } if (!str.contains("MapsCollectionStorage")) { - _mapStorages.clear(); while ((str = reader.readLine()) != null) { String[] elem = str.split(String.format("\\%c", separatorDict)); AbstractMap map = switch (elem[1]) { @@ -131,23 +140,26 @@ public class MapsCollection { case "WaterMap" -> new WaterMap(); default -> null; }; - _mapStorages.put(elem[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map)); if (elem.length == 3) { + _mapStorages.get(elem[0]).LoadData(elem[2].split(String.format("%c", separatorData))); } } } else { String[] data = reader.readLine().split(":"); - if (_mapStorages.containsKey(data[0])) { - _mapStorages.remove(data[0]); - } + AbstractMap map = switch (data[1]) { case "SimpleMap" -> new SimpleMap(); case "WaterMap" -> new WaterMap(); default -> null; }; - _mapStorages.put(data[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map)); + if (_mapStorages.containsKey(data[0])) { + _mapStorages.get(data[0]).Clear(); + } + else { + _mapStorages.put(data[0], new MapWithSetBusesGeneric<>(_pictureWidth, _pictureHeight, map)); + } String k = reader.readLine(); while (k != null) { _mapStorages.get(data[0]).LoadData(k); diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java index 55591a4..054647c 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java @@ -59,6 +59,10 @@ class SetBusesGeneric { public int Count() { return _places.size(); } + + public void Clear() { + _places.clear(); + } }