WIP: Rework DataMan constructors.
Method to get all saved times. Not working.
This commit is contained in:
parent
270e89ee5b
commit
9280a5b4b3
@ -6,19 +6,10 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class DataManeger {
|
public class DataManeger {
|
||||||
|
|
||||||
private Path workingDir;
|
private File workingDir;
|
||||||
|
|
||||||
// public DataManeger(Path path) {
|
|
||||||
// this.seperator = File.separatorChar;
|
|
||||||
// this.workingDir = path;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public DataManeger(State state, Date time){
|
|
||||||
Path dir = Paths.get("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataManeger(){
|
public DataManeger(){
|
||||||
this(null, null);
|
workingDir = new File(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean stateAvailable(Date time) {
|
public boolean stateAvailable(Date time) {
|
||||||
@ -31,7 +22,7 @@ public class DataManeger {
|
|||||||
if (stateAvailable(time)){
|
if (stateAvailable(time)){
|
||||||
try {
|
try {
|
||||||
ObjectInputStream objectInputStream = new ObjectInputStream(
|
ObjectInputStream objectInputStream = new ObjectInputStream(
|
||||||
new FileInputStream(String.format("0x%016X.bin", time.getTime())));
|
new FileInputStream(String.format("%016X.bin", time.getTime())));
|
||||||
state = (State)objectInputStream.readObject();
|
state = (State)objectInputStream.readObject();
|
||||||
objectInputStream.close();
|
objectInputStream.close();
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
@ -43,7 +34,7 @@ public class DataManeger {
|
|||||||
|
|
||||||
public boolean saveState(State state, Date time){
|
public boolean saveState(State state, Date time){
|
||||||
try {
|
try {
|
||||||
FileOutputStream fs = new FileOutputStream(String.format("0x%016X.bin", time.getTime()));
|
FileOutputStream fs = new FileOutputStream(String.format("%016X.bin", time.getTime()));
|
||||||
BufferedOutputStream bfs = new BufferedOutputStream(fs);
|
BufferedOutputStream bfs = new BufferedOutputStream(fs);
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs);
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs);
|
||||||
objectOutputStream.writeObject(state);
|
objectOutputStream.writeObject(state);
|
||||||
@ -54,6 +45,26 @@ public class DataManeger {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File[] savedStateFiles() {
|
||||||
|
return workingDir.listFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date[] savedStatesTimes() {
|
||||||
|
File[] files = savedStateFiles();
|
||||||
|
ArrayList<Date> timesList = new ArrayList<>();
|
||||||
|
for (File file : files){
|
||||||
|
if (file.getName().contains(".bin")){
|
||||||
|
String timeInName = file.getName().replaceAll(".bin", "").trim();
|
||||||
|
if ("".equals(timeInName)) continue;
|
||||||
|
long time = Long.parseLong(timeInName, 16);
|
||||||
|
timesList.add(new HijriDate(time));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Date[] times = new Date[timesList.size()];
|
||||||
|
times = timesList.toArray(times);
|
||||||
|
return times;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class State implements Serializable {
|
class State implements Serializable {
|
||||||
|
@ -209,12 +209,12 @@ public class MakkahCity {
|
|||||||
btnBrowseHistory.setForeground(Color.white);
|
btnBrowseHistory.setForeground(Color.white);
|
||||||
|
|
||||||
//Label
|
//Label
|
||||||
JLabel lblStreets = new JLabel("Streets History");
|
JLabel lblStreets = new JLabel("Streets");
|
||||||
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
lblStreets.setForeground(new Color(255, 255, 255));
|
lblStreets.setForeground(new Color(255, 255, 255));
|
||||||
lblStreets.setBounds(49, 59, 208, 30);
|
lblStreets.setBounds(49, 59, 208, 30);
|
||||||
|
|
||||||
JLabel lblDistrict = new JLabel("District History");
|
JLabel lblDistrict = new JLabel("District");
|
||||||
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
lblDistrict.setForeground(new Color(255, 255, 255));
|
lblDistrict.setForeground(new Color(255, 255, 255));
|
||||||
lblDistrict.setBounds(49, 438, 166, 29);
|
lblDistrict.setBounds(49, 438, 166, 29);
|
||||||
@ -472,17 +472,6 @@ public class MakkahCity {
|
|||||||
startMenu();
|
startMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Vehicle traceCar() {
|
|
||||||
|
|
||||||
for(int x = 20000; x < listOfVehicles.size(); x++) {
|
|
||||||
if(listOfVehicles.get(x) instanceof Bus)
|
|
||||||
if(((Bus)listOfVehicles.get(x)).getCampaign().getHotelDistrict() == District.ALAZIZIYA) {
|
|
||||||
return listOfVehicles.get(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkInput() {
|
private static void checkInput() {
|
||||||
String input = "";
|
String input = "";
|
||||||
if (exit_flag) System.exit(0);
|
if (exit_flag) System.exit(0);
|
||||||
@ -1175,6 +1164,7 @@ public class MakkahCity {
|
|||||||
allArrivedToHotelsTime);
|
allArrivedToHotelsTime);
|
||||||
DataManeger dataManeger = new DataManeger();
|
DataManeger dataManeger = new DataManeger();
|
||||||
dataManeger.saveState(s, 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());
|
boolean result = dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
||||||
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
|
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
|
||||||
|
Loading…
Reference in New Issue
Block a user