/*
* Create.java
* The package functions contains the different class executing the different functions of the FlightSystem Reservation.
*/
package reservation.system.functions;
import reservation.system.Flight;
import java.util.HashSet;
import java.util.Set;
/**
* This class hold Create structure. This object allows to create a new flight in the data base by calling the method <CODE>create</CODE> in {@link reservation.system.FlightSystem}.
* @author Texier Mathieu and Frederic Bidon
*/
public class Create extends Functions {
/**
* Create a new flight in a database if the command <CODE>create</CODE> and their arguments are correct.
* @throws Exception if the flight is not created.
* @return a confimation's message if the flight is created.
*/
if (fs.
create (arg
[0],
(short) Integer.
parseInt (arg
[1]),
(short)
return "Flight created \r\n";
else {throw new Exception ("The flight is not succesfully created");}
}
/**
* Verify invariants :
* <PRE>
* - Arguments not null
* - <CODE>rows</CODE> belongs to [1 <CODE>Flight.ROWS_MAX</CODE>]
* - <CODE>rowsLength</CODE> belongs to [1 <CODE>Flight.ROW_LENGTH_MAX</CODE>]
* </PRE>
* @throws Exception if the invariants is violated
*/
try {
ArgumentIsValid (arg, 3, 3);
if (!checkInteger (arg[1], 1, Flight.ROWS_MAX))
throw new Exception ("The argument : rows has to be a number");
if (!checkInteger (arg[2], 1, Flight.ROW_LENGTH_MAX))
throw new Exception ("The argument : rows length has to be a number");
throw new Exception (e.
getMessage ()+ "\r\n" + usage
());
}
}
/**
* Display the usage for the command <CODE>create</code>.
* @return the usage.
*/
static public String usage
() {
String usage
= " Usage command create: create <flightName> <rows> <rowLength>\n\r";
usage += " - The <flightName> can contain all the characters except the special \r\n";
usage += " character. \r\n";
usage += " - The argument <rows> is a number that belongs to [1 100].\r\n";
usage += " - The argument <rowLength> is a number that belongs to [1 10].\n";
return usage;
}
}