diff --git a/src/DataManeger.java b/src/DataManeger.java index af66508..84fcb03 100644 --- a/src/DataManeger.java +++ b/src/DataManeger.java @@ -22,7 +22,7 @@ public class DataManeger { } public boolean stateAvailable(Date time) { - File f = new File(workingDir.toString()+time.getTime()); + File f = new File(String.format("0x%016X.bin", time.getTime())); return f.exists(); } @@ -31,7 +31,7 @@ public class DataManeger { if (stateAvailable(time)){ try { ObjectInputStream objectInputStream = new ObjectInputStream( - new FileInputStream(String.format("%s%d",workingDir,time.getTime()))); + new FileInputStream(String.format("0x%016X.bin", time.getTime()))); state = (State)objectInputStream.readObject(); objectInputStream.close(); } catch (IOException | ClassNotFoundException e) { @@ -43,7 +43,7 @@ public class DataManeger { public boolean saveState(State state, Date time){ try { - FileOutputStream fs = new FileOutputStream(String.format("%s%d",workingDir,time.getTime())); + FileOutputStream fs = new FileOutputStream(String.format("0x%016X.bin", time.getTime())); BufferedOutputStream bfs = new BufferedOutputStream(fs); ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs); objectOutputStream.writeObject(state); diff --git a/src/MakkahCity.java b/src/MakkahCity.java index defaf5f..87aea79 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -164,8 +164,9 @@ public class MakkahCity { "[3] View Campaigns\n" + "[4] View Routes\n" + "[5] Print report\n" + - "[6] Continue\n" + - "[7] Exit"); + "[6] Browse History\n" + + "[7] Continue\n" + + "[8] Exit"); String choice = in.next(); //Split into methods? if (choice.equals("1")){ @@ -198,8 +199,9 @@ public class MakkahCity { } } if (choice.equals("5")) System.out.println(getStreetsReport()); - if (choice.equals("6")) return; - if (choice.equals("7")) { + if (choice.equals("6")) browseHistory(); + if (choice.equals("7")) return; + if (choice.equals("8")) { inputListener.stop(); t.interrupt(); System.exit(0); @@ -276,6 +278,46 @@ public class MakkahCity { System.out.println(route.toString()); } + private static void browseHistory() { + Calendar dummyCal = new GregorianCalendar(); + dummyCal.setTime(currenttimeManager.getCurrentTime()); + //dummyCal.roll(Calendar.HOUR, -1); + dummyCal.set(Calendar.MINUTE, 0);//Go down to last hour. + Scanner in = new Scanner(System.in); + boolean selected = false; + while (!selected){ + System.out.println(new HijriDate(dummyCal.getTimeInMillis())); + System.out.print("[1] Forward\n" + + "[2] Backward\n" + + "[3] Select\n" + + "[4] Return\n"); + String choice = in.next(); + if (choice.equals("1")) dummyCal.roll(Calendar.HOUR, 1); + if (choice.equals("2")) dummyCal.roll(Calendar.HOUR, -1); + if (choice.equals("3")) { + selected = true; + DataManeger dataManeger = new DataManeger(); + if (dataManeger.stateAvailable(dummyCal.getTime())) { + State state = dataManeger.loadState(dummyCal.getTime()); + System.out.print(dummyCal.getTime() + " (History)\n"); + System.out.println("\n"+ + "---------------------------\n" + + "[1] View Buses\n" + + "[2] View Streets\n" + + "[3] View Campaigns\n" + + "[4] View Routes\n"); + choice = in.next(); + if (choice.equals("1")){ + System.out.print("0 - "+state.getListOfVehicles().size()); + choice = in.next(); + showVehicle(state.getListOfVehicles().get(Integer.parseInt(choice))); + } + } else System.out.print("Not saved"); + } + } + + } + private static void clearDoneCivilVehicles() { //Clear civil cars from list for (int i = 0; i < listOfVehicles.size();){