📄 reload.java
字号:
/* * Reload.java * The package functions contains the different class executing the different functions of the FlightSystem Reservation. */package reservation.system.functions;import reservation.system.FlightSystem;import reservation.system.Flight;import reservation.system.Pos;import reservation.system.Person;import java.io.*;import java.util.Vector;/** * This class hold Reload structure. This object allows to load the data previous saved in a file. * @author Texier Mathieu and Frederic Bidon */ public class Reload extends Functions { /**Name of the file to reload*/ private File datafile; /** * Verify invariants : * <PRE> * - Argument not null * - The number of argument equals 1 * - File's name exists * - The file can be read * </PRE> * @throws Exception if the file doesn't exist or cannot read. */ void _check (String[] arg) throws Exception { ArgumentIsValid (arg, 1, 1); File datafile = new File (arg[0]); if (!datafile.exists () || !datafile.canRead () ) { throw new Exception ("file " + datafile.getPath () + " does not exist or can not be read"); } else this.datafile = datafile; } /** * Display the usage for the command <CODE>reload</code>. * @return the usage. */ static public String usage() { String usage = " Usage command Reload: reload <fileName>\n\r"; usage += " - The <fileName> is the path to the file to be reloaded \n\r"; usage +=" The file extention is .out .\n"; return usage; } /** * Reload the data previous stored in a file. * @throws Exception if the file is not reloaded. * @return a confimation's message if the data are reloaded. */ public String execute () throws Exception { String reString = "FlightSystem reloaded"; ObjectInputStream fin = new ObjectInputStream (new FileInputStream (arg[0])); Object obj = fin.readObject (); if (obj instanceof FlightSystem) { FlightSystem fsExtracted = (FlightSystem) obj; String[] listFlight = fsExtracted.getFlightList (); int decount = listFlight.length; for(int i = 0; i < listFlight.length; i++) { Flight flight = fsExtracted.selectFlight (listFlight[i]); decount -= fs.create (flight)? 1 : 0; } if (decount != 0) throw new Exception ("Flight list partialy reloaded: " + decount + "flight skiped"); Integer[] listBooking = fsExtracted.getBookingList (); for (int j = 0; j < fsExtracted.getBookingNumberMax (); j++) { Vector listPerson = fsExtracted.identify (listBooking[j].intValue ()); decount += listPerson.size(); for (int k = 0; k < listPerson.size (); k++) { Person person = (Person) listPerson.get (k); decount -= fs.reserve (person); } } if (decount != 0) throw new Exception ("Person list partialy reloaded: " + decount + "person skiped"); fin.close (); } return reString; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -