DataManeger:
- DataManeger is static global var in Makkah. - Save states in data/ dir. - Clear all bin files with constructor.
This commit is contained in:
parent
9a610b65e6
commit
ab3acdec9b
@ -9,11 +9,13 @@ public class DataManeger {
|
||||
private File workingDir;
|
||||
|
||||
public DataManeger(){
|
||||
workingDir = new File(".");
|
||||
workingDir = new File("./data/");
|
||||
workingDir.mkdir();
|
||||
clearData();
|
||||
}
|
||||
|
||||
public boolean stateAvailable(Date time) {
|
||||
File f = new File(String.format("0x%016X.bin", time.getTime()));
|
||||
File f = new File(String.format("./data/%s.bin", time.getTime()));
|
||||
return f.exists();
|
||||
}
|
||||
|
||||
@ -22,7 +24,7 @@ public class DataManeger {
|
||||
if (stateAvailable(time)){
|
||||
try {
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(
|
||||
new FileInputStream(String.format("%016X.bin", time.getTime())));
|
||||
new FileInputStream(String.format("./data/%s.bin", time.getTime())));
|
||||
state = (State)objectInputStream.readObject();
|
||||
objectInputStream.close();
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
@ -34,7 +36,7 @@ public class DataManeger {
|
||||
|
||||
public boolean saveState(State state, Date time){
|
||||
try {
|
||||
FileOutputStream fs = new FileOutputStream(String.format("%016X.bin", time.getTime()));
|
||||
FileOutputStream fs = new FileOutputStream(String.format("./data/%s.bin", time.getTime()));
|
||||
BufferedOutputStream bfs = new BufferedOutputStream(fs);
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs);
|
||||
objectOutputStream.writeObject(state);
|
||||
@ -57,7 +59,7 @@ public class DataManeger {
|
||||
if (file.getName().contains(".bin")){
|
||||
String timeInName = file.getName().replaceAll(".bin", "").trim();
|
||||
if ("".equals(timeInName)) continue;
|
||||
long time = Long.parseLong(timeInName, 16);
|
||||
long time = Long.parseLong(timeInName);
|
||||
timesList.add(new HijriDate(time));
|
||||
}
|
||||
}
|
||||
@ -65,6 +67,14 @@ public class DataManeger {
|
||||
times = timesList.toArray(times);
|
||||
return times;
|
||||
}
|
||||
|
||||
private void clearData() {
|
||||
for (File file : savedStateFiles()) {
|
||||
if (file.getName().contains(".bin")){
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class State implements Serializable {
|
||||
|
@ -31,6 +31,7 @@ public class MakkahCity {
|
||||
private static final InputListener inputListener = new InputListener();
|
||||
private static final Thread t = new Thread(inputListener,"InputThread-Makkah");
|
||||
private static boolean isAllRoutSet;
|
||||
private static final DataManeger dataManeger = new DataManeger();
|
||||
//GUI
|
||||
private static boolean exit_flag;
|
||||
private static boolean pause_flag;
|
||||
@ -1162,7 +1163,6 @@ public class MakkahCity {
|
||||
stdStreet,
|
||||
allArrivedToArafatTime,
|
||||
allArrivedToHotelsTime);
|
||||
DataManeger dataManeger = new DataManeger();
|
||||
dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
||||
System.out.println(Arrays.toString(dataManeger.savedStatesTimes())); //TODO FOR DEBUG REMOVE
|
||||
|
||||
@ -1170,11 +1170,6 @@ public class MakkahCity {
|
||||
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
|
||||
}
|
||||
|
||||
private static State loadState(Date time){
|
||||
DataManeger dataManeger = new DataManeger();
|
||||
return dataManeger.loadState(time);
|
||||
}
|
||||
|
||||
private static void updateStreetFrame() {
|
||||
Object[][] streetData = new Object[stdStreet.length][6];
|
||||
for (int i = 0; i < stdStreet.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user