📄 command.java
字号:
/* * Command.java * The package reservation contains the different class allowing to choose the action to realise. */package reservation;import reservation.system.functions.*;import java.util.StringTokenizer;import java.io.InputStreamReader;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;/** * This class hold Command structure. This object analyse the instruction written by the user and determine according to the first element the command to execute. * Then it instancie a new object which depends to the command and which will execute the instruction of the user. * @author Texier Mathieu and Frederic Bidon */public class Command implements Mode{ /** Creates a new instance of Command */ public Command () { } /** * Take over the instruction written by the user and also if it want execute the command in Verbose Mode * @param in The input stream from which the data are interpreted * @param VerboseMode the verbosity level (QUIET, NORMAL, DEBUG) */ public Command (BufferedReader in, int VerboseMode) { this.in = in; this.VerboseMode = VerboseMode; } /** * This method determine the number of element of the user's instruction and analyse the first element of this one. * If it corresponds to an available command of the system, it create a new object depending of the command. * This new object will execute the instruction with the other elements of the command. */ public void process () { Action action = null; boolean escape = false; do { boolean boolError = false; StringTokenizer st = null; do { try { if (VerboseMode > QUIET) System.out.print ("CMD>"); String readLine = in.readLine (); if (readLine == null) return; st = new StringTokenizer (readLine); } catch (IOException e){ System.err.println (e);} } while (st.countTokens () < 1); int AgumentNumber= st.countTokens ()-1; String line[] = new String[AgumentNumber]; String Command = st.nextToken ().toLowerCase (); for (int i = 0;st.hasMoreTokens (); i++) line[i] = st.nextToken (); try { if (Command.equals ("create")) action = new Create (); else if (Command.equals ("reserve")) action = new Reserve (); else if (Command.equals ("list")) action = new Lists (); else if (Command.equals ("identify")) action = new Identify (); else if (Command.equals ("cancel")) action = new Cancel (); else if (Command.equals ("flights")) action = new Flights (); else if (Command.equals ("store")) action = new Store (); else if (Command.equals ("reload")) action = new Reload (); else if (Command.equals ("exit")) { Functions.ArgumentIsValid (line, 0, 0); escape = true; } else {throw new Exception ("This command doesn't exist.");} } catch (Exception e) { System.err.println (e.getMessage ()); if (VerboseMode > HIGH) { e.printStackTrace (); } boolError = true; } System.out.flush (); String res = ""; try { if (!boolError && !escape) { res = action.execute (line); } if (VerboseMode > QUIET) System.out.println (res); if (VerboseMode > NORMAL) System.out.println (Action.fs); } catch (Exception e) { System.err.println (e.getMessage ()); if (VerboseMode > HIGH) e.printStackTrace (); } System.err.flush (); } while (!escape) ; } private BufferedReader in = new BufferedReader (new InputStreamReader (System.in)); private int VerboseMode = NORMAL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -