diff --git a/src/DataManeger.java b/src/DataManeger.java index 4934606..a8bdd53 100644 --- a/src/DataManeger.java +++ b/src/DataManeger.java @@ -1,8 +1,7 @@ import java.io.*; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Date; +import java.util.List; public class DataManeger { @@ -68,6 +67,24 @@ public class DataManeger { return times; } + public List getStates(){ + List list = new ArrayList<>(); + for (File file : workingDir.listFiles()) { + if (file.getName().contains(".bin")){ + try { + FileInputStream fileInputStream = new FileInputStream(file); + BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream); + ObjectInputStream objectInputStream = new ObjectInputStream(bufferedInputStream); + State state = (State) objectInputStream.readObject(); + list.add(state); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + return list; + } + private void clearData() { for (File file : savedStateFiles()) { if (file.getName().contains(".bin")){ @@ -87,8 +104,15 @@ class State implements Serializable { private Street[] stdStreet; private Date allArrivedToArafatTime; private Date allArrivedToHotelsTime; + private Date stateTime; - public State(ArrayList listOfCampaigns, ArrayList listOfVehicles, Route[] stdRoutes, Street[] stdStreet, Date allArrivedToArafatTime, Date allArrivedToHotelsTime) { + public State(ArrayList listOfCampaigns, + ArrayList listOfVehicles, + Route[] stdRoutes, + Street[] stdStreet, + Date allArrivedToArafatTime, + Date allArrivedToHotelsTime, + Date stateTime) { //Make clones since values may change if this is running on a thread. this.listOfCampaigns = (ArrayList) listOfCampaigns.clone(); this.listOfVehicles = (ArrayList) listOfVehicles.clone(); @@ -100,6 +124,7 @@ class State implements Serializable { if (allArrivedToHotelsTime != null) { this.allArrivedToHotelsTime = (Date) allArrivedToHotelsTime.clone(); } + this.stateTime = stateTime; } public ArrayList getListOfCampaigns() { diff --git a/src/MakkahCity.java b/src/MakkahCity.java index 33b1071..d93dcb9 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -1162,9 +1162,9 @@ public class MakkahCity { stdRoutes, stdStreet, allArrivedToArafatTime, - allArrivedToHotelsTime); + allArrivedToHotelsTime, + currenttimeManager.getCurrentTime()); dataManeger.saveState(s, currenttimeManager.getCurrentTime()); - System.out.println(Arrays.toString(dataManeger.savedStatesTimes())); //TODO FOR DEBUG REMOVE boolean result = dataManeger.saveState(s, currenttimeManager.getCurrentTime()); if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());