booking system

  1. /*
  2.  * Pos.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 Pos structure. This object define the dimention of a {@link reservation.system.Flight} and the seat for a <CODE> {@link reservation.system.Person}</CODE>.
  11.  * @author Texier Mathieu and Frederic Bidon
  12.  */
  13. public class Pos extends Object implements Cloneable, Serializable {
  14.     /**
  15.      * Construct a <CODE>Pos</CODE> object.
  16.      * @param row The number of <CODE>rows</CODE> for a {@link reservation.system.Flight} and the row of the seat for a {@link reservation.system.Person}.
  17.      * @param col The length of a <CODE>row</CODE> for a {@link reservation.system.Flight} and the col of the seat for a {@link reservation.system.Person}.
  18.      * @throws Exception When value dosn't make sense, this exception is thrown
  19.      */
  20.     public Pos (short row, short col) throws Exception {
  21.         this.row = row;
  22.         this.col = col;
  23.         _check ();
  24.     }
  25.    
  26.     /**
  27.      * Return The number of <CODE>rows</CODE> for a {@link reservation.system.Flight} and the row of the seat for a {@link reservation.system.Person}.
  28.      * @return the row
  29.      * @throws Exception when the invariant is violated
  30.      */
  31.     public short getRow () throws Exception {
  32.         _check ();
  33.         return row;
  34.     }
  35.    
  36.      /**
  37.       * Return The length of a <CODE>row</CODE> for a {@link reservation.system.Flight} and the col of the seat for a {@link reservation.system.Person}.
  38.       * @return the col
  39.       * @throws Exception when the invariant is violated
  40.       */
  41.     public short getCol () throws Exception {
  42.         _check ();
  43.         return col;
  44.     }
  45.    
  46.      /**
  47.      * Overide equals
  48.      * @return <CODE>true</CODE> if this object is the same as the obj argument;
  49.      * <CODE>false</CODE> otherwise
  50.      * @param anObject <CODE>anObject</CODE> - the reference object with which to compare
  51.      */  
  52.     public boolean equals (Object anObject) {
  53.         if (anObject != null && anObject instanceof Pos) {
  54.             Pos pos = (Pos) anObject;
  55.             return ((this.row == pos.row) && (this.col == pos.col));
  56.         }
  57.         else
  58.             return false;
  59.     }
  60.    
  61.      /**
  62.      * Returns a string representation of this <CODE>Flight</CODE> object. This method
  63.      * is intended to be used only for debugging purposes, and the content and format
  64.      * of the returned string may vary between implementations. The returned string may
  65.      * be empty but may not be <CODE>null</CODE>
  66.      * @return a string representation of this <CODE>Pos</CODE> object.
  67.      */  
  68.     public String toString () {
  69.         return "("+row+","+col+")";
  70.     }
  71.    
  72.     /**
  73.      * Creates and returns a copy of this object.
  74.      * @return a copy of this <CODE>Pos</CODE> object
  75.      * @throws CloneNotSupportedException if the object's class does not support the <CODE>Cloneable</CODE> interface.
  76.      */    
  77.     protected Object clone () throws CloneNotSupportedException {
  78.         try {
  79.             return new Pos (row, col);
  80.         } catch (Exception e){System.err.println (e);return null;}
  81.     }
  82.    
  83.      /**
  84.      * Verify invariants :
  85.      * <PRE>
  86.      * - dimension > 0
  87.      * </PRE>
  88.      * @throws Exception if the invariant is violated
  89.      */  
  90.     public void _check () throws Exception {
  91.         if (row <= 0 || col <= 0)
  92.             throw new Exception ("Position has a negative or null value");
  93.     }
  94.    
  95.     private short row;
  96.     private short col;
  97. }

contact - link to this site