/*
* Identify.java
* The package functions contains the different class executing the different functions of the FlightSystem Reservation.
*/
package reservation.system.functions;
import reservation.system.Person;
import java.util.Vector;
/**
* This class hold Lists structure. This object allows to see the person who are registered in one flight by calling the method <CODE>list</CODE> in {@link reservation.system.FlightSystem}.
* @author Texier Mathieu and Frederic Bidon
*/
public class Identify extends Functions {
/**
* Display the list of the persons who have got the bookingNumber written by the user if the command <CODE>identify</CODE> and their arguments are correct.
* @throws Exception the command is not executed.
* @return the names of the persons which correpond to this bookingNumber and their positions in the flight.
*/
Vector groupePersonVector
= fs.
identify (Integer.
parseInt (arg
[0]));
if (groupePersonVector.isEmpty ())
return "The List is empty.\r\n";
String flightName
= ((Person
) groupePersonVector.
get (0)).
getFlight ().
getFlightName ();
String retString
= "Flight: Identify " + arg
[0] + " (flght " + flightName
+" )\r\n" ;
for (int i=0; i< groupePersonVector.size (); i++)
retString += (Person) groupePersonVector.get (i);
return retString;
}
/**
* Verify that at least one flight is created and also one reservation has been made.
* Verify invariants :
* <PRE>
* - Arguments not null
* - <CODE>bookingNumber</CODE> belongs to [1 <CODE>fs.getBookingNumberMax</CODE>]
* </PRE>
* @throws Exception if the invariants is violated
*/
try {
CheckFlightListNotEmpty ();
CheckBookingListNotEmpty ();
ArgumentIsValid (arg, 1, 1);
if (!checkInteger (arg[0], 1, fs.getBookingNumberMax ()))
throw new Exception ("The argument booking number has to be an integer");
throw new Exception (e.
getMessage ()+ "\r\n" + usage
());
}
}
/**
* Display the usage for the command <CODE>identify</code>.
* @return the usage.
*/
static public String usage
() {
String usage
= " Usage command identify: identify <bookingNumber>\n\r";
usage += " - The <bookingNumber> is a number and cannot be inferior to 0.\n";
return usage;
}
}