📄 functions.java
字号:
/* * Functions.java * The package functions contains the different class executing the different functions of the FlightSystem Reservation. */package reservation.system.functions;/** * This class uniform the way to call each sub-class (Create, Reserve, Cancel, Lists, Identify) that processes the commands. * It delegates to the sub-class the implementation of the function execute () and check (). * Also it masks the machinery and helps the developer who want to reuse the program. * @author Texier Mathieu and Frederic Bidon */public abstract class Functions extends Object implements reservation.Action { /** * Proceed the execution of the request * @throws Exception if the excution is not complete * @return The apropriate description */ public abstract String execute () throws Exception; /** * Display the usage for the command (details the different arguments, his type...). * @return the Usage */ static public String usage (){ return new String (Create.usage () + "\r\n" + Reserve.usage ()+ "\r\n" + Cancel.usage () + "\r\n" + Identify.usage () + "\r\n" + Lists.usage () + "\r\n" + Store.usage () + "\r\n" + Reload.usage () + "\r\n"); } /** * Process the array of argument * @return the result of the request. * @throws Exception If the command is not executed * @param arg the list of command to be proceed */ public String execute(String[] arg) throws Exception { this.arg = (String[]) arg.clone (); _check (arg); return execute (); } /** * Verify invariants : * <PRE> * - <CODE>regex</CODE> ^0*[1-9]+0* * * - <CODE>arg</CODE> belongs to [min max] * </PRE> * @return false if the invariants is violated * @param min the minimun number allowed in <CODE>arg</CODE> * @param max the maximum number allowed in <CODE>arg</CODE> * @param arg the input String that will be checked */ static public boolean checkInteger (String arg, int min, int max) { if (arg.matches ("^0*[1-9]+0*")) return ((Integer.parseInt (arg) >= min) && (Integer.parseInt (arg) <= max)) ; return false; } /** * Verify the number of arguments of the command * Verify invariants : * <PRE> * - <CODE>regex</CODE> ^[A-Z][a-z]* * - seat < dimension of the flight and > 0 * </PRE> * @param arg the input array that will be checked * @param min the minimum argument allowed in <CODE>arg</CODE> * @param max the maximum argument allowed in <CODE>arg</CODE> * @throws Exception if the invariants is violated */ public static void ArgumentIsValid (String[] arg, int min, int max) throws Exception { boolean badFormat = false; if (arg != null) { for (int i = 0; i < arg.length; i++) { if (arg[i] == null) throw new IllegalArgumentException ("The command can not have null parameter\r\n"); } if (arg.length < min || arg.length > max) badFormat = true; } else badFormat = true; if (badFormat) throw new IllegalArgumentException ("The number of argument for this method is not correct\r\n"); } /** * Verify that at least one flight is created. * @throws Exception if the FlightList contains no flight. */ static void CheckFlightListNotEmpty () throws Exception { if (fs.getFlightList ().length <= 0) throw new Exception ("Please create a flight first"); } /** * Verify that one reservation has been made. * @throws Exception if the BookingList contains no BookingNumber. */ static void CheckBookingListNotEmpty () throws Exception { if (fs.getBookingList ().length <= 0) throw new Exception ("Please reserve for a person first;"); } /** * Check if the arguments are correct and can be executed * @throws Exception if the argument is violated */ abstract void _check (String[] arg) throws Exception; /** * The list of argnument receive from the command */ protected String[] arg;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -