This the part where I use the serialisable interface. when I start the program it will create the same object for each list, but with different references. Is there any way to get them all as one reference?
private static void quitApplication(){
System.out.println("Stopping the system...\n");
///store all the objects by serializing
try {
FileOutputStream fileOut2 = new FileOutputStream("FlightList.ser");
ObjectOutputStream out2 = new ObjectOutputStream(fileOut2);
out2.writeObject(Flight.getFlights());
out2.close();
fileOut2.close();
}catch(IOException i) {
System.out.println("FlightList.ser ERROR");
}
try {
FileOutputStream fileOut = new FileOutputStream("CityList.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(City.getCityList());
out.close();
fileOut.close();
}catch(IOException i) {
System.out.println("CityList.ser ERROR");
}
try {
FileOutputStream fileOut1 = new FileOutputStream("GrapghL.ser");
ObjectOutputStream out1 = new ObjectOutputStream(fileOut1);
out1.writeObject(Test.flightGraph);
out1.close();
fileOut1.close();
}catch(IOException i) {
System.out.println("GrapghL.ser ERROR");
}
System.out.println("Done...Thank You For using the Airlines System");
}
private static void initializeData(){
try {
FileInputStream fileIn = new FileInputStream("CityList.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
City.setCityList((MyList<City>) in.readObject());
in.close();
fileIn.close();
}catch(Exception i){
System.out.println("CityList.ser ERROR");
}
try {
FileInputStream fileIn2 = new FileInputStream("FlightList.ser");
ObjectInputStream in2 = new ObjectInputStream(fileIn2);
Flight.setFlights((MyList<Flight>) in2.readObject());
in2.close();
fileIn2.close();
}catch(Exception i){
System.out.println("FlightList.ser ERROR");
}
try {
FileInputStream fileIn1 = new FileInputStream("GrapghL.ser");
ObjectInputStream in1 = new ObjectInputStream(fileIn1);
Test.flightGraph = (DefaultDirectedWeightedGraph<City, DefaultWeightedEdge>) in1.readObject();
in1.close();
fileIn1.close();
}catch(Exception i){
System.out.println("GrapghL.ser ERROR");
}
}