booking system

  1. /*
  2.  * Flight.java
  3.  * The package system contains the different class allowing to create and to select the object to store in the database.
  4.  */
  5. package reservation.system;
  6.  
  7. import java.io.Serializable;
  8.  
  9. /**
  10.  * This class hold fligth structure. This object could be asserted in the <CODE>FlightList</CODE>.
  11.  * @author Texier Mathieu and Frederic Bidon
  12.  */
  13. public class Flight extends Object implements Cloneable, Serializable{
  14.     /**
  15.      * The maximum number of rows in a <CODE>flight</CODE>
  16.      */
  17.     final static public int ROWS_MAX = 100;
  18.     /**
  19.      * The maximum number of length of each row in a <CODE>flight</CODE>
  20.      */
  21.     final static public int ROW_LENGTH_MAX = 10;
  22.    
  23.     /**
  24.      * Construct a <CODE>Flight</CODE> named <CODE>flightName</CODE> with the size <CODE>dimension</CODE>
  25.      * @param flightName Name of the flight. This name is used to {@link  reservation.system.functions.Lists} the flight
  26.      * @param dimension The size of the flight : number of rows and row length
  27.      * @throws Exception When value dosn't make sense, this exception is thrown
  28.      */
  29.     public Flight (String flightName, Pos dimension)  throws Exception{
  30.         this.flightName = flightName;
  31.         this.dimension = (Pos) dimension.clone ();
  32.         _check ();
  33.     }
  34.    
  35.     /**
  36.      * Return the name of the <CODE>fligth</CODE>
  37.      * @return the name of the flight
  38.      */
  39.     public String getFlightName () {
  40.         return flightName;
  41.     }
  42.    
  43.     /**
  44.      * Return the <CODE>dimension</CODE> (Rows and row length) of the <CODE>flight</CODE>
  45.      * @return the dimension of the flight
  46.      */
  47.     public Pos getDimension () {
  48.         return dimension;
  49.     }
  50.    
  51.     /**
  52.      * Returns a string representation of this <CODE>Flight</CODE> object. This method
  53.      * is intended to be used only for debugging purposes, and the content and format
  54.      * of the returned string may vary between implementations. The returned string may
  55.      * be empty but may not be <CODE>null</CODE>
  56.      * @return a string representation of this <CODE>Flight</CODE> object.
  57.      */
  58.     public String toString () {
  59.         return flightName +" "+ dimension;
  60.     }
  61.    
  62.     /**
  63.      * Overide equals
  64.      * @return <CODE>true</CODE> if this object is the same as the obj argument;
  65.      * <CODE>false</CODE> otherwise
  66.      * @param anObject <CODE>anObject</CODE> - the reference object with which to compare
  67.      */
  68.     public boolean equals (Object anObject) {
  69.         if (anObject != null && anObject instanceof Flight) {
  70.             Flight flight = (Flight) anObject;
  71.             return (flightName.equals (flight.flightName) && dimension.equals (flight.dimension));
  72.         }
  73.         else
  74.             return false;
  75.     }
  76.    
  77.     /**
  78.      * Creates and returns a copy of this object.
  79.      * @return a copy of this <CODE>Flight</CODE> object
  80.      * @throws CloneNotSupportedException if the object's class does not support the <CODE>Cloneable</CODE> interface.
  81.      */
  82.     protected Object clone () throws CloneNotSupportedException {
  83.         try {
  84.             _check ();
  85.             return new Flight (flightName, dimension);
  86.         } catch ( Exception e) {System.err.println (e);return null;}
  87.     }
  88.    
  89.     /**
  90.      * Verify invariants :
  91.      * <PRE>
  92.      * - <CODE>regex</CODE> [[A-Z]*[a-z]*[0-9]*]+<BR>
  93.      * - dimension < (<CODE>ROWS_MAX</CODE>,<CODE>ROWS_LENGHT_MAX</CODE>) and > 0
  94.      * </PRE>
  95.      * @throws NullPointerException if pos or name is null
  96.      * @throws Exception if the invariant is violated
  97.      */
  98.     public void _check () throws Exception, NullPointerException{
  99.         if (flightName == null || dimension == null)
  100.             throw new NullPointerException ("The flight "+ this +" has an null value.") ;
  101.        
  102.         if (dimension.getRow () < 1 || dimension.getRow () > ROWS_MAX
  103.         || dimension.getCol () < 1 || dimension.getCol () > ROW_LENGTH_MAX
  104.         )
  105.             throw new NullPointerException ("The flight "+ this +" has an out of range value.") ;
  106.        
  107.         if (!flightName.matches ("[[A-Z]*[a-z]*[0-9]*]+"))
  108.             throw new Exception ("The flight name : " + flightName + " has illegal character") ;
  109.     }
  110.    
  111.     private String flightName;
  112.     private Pos dimension;
  113. }
  114.  

contact - link to this site