booking system

  1. /*
  2.  * Profile.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. /**
  8.  * The overall idea of this class is to provide a method of comparison between a person and an incomplete Person structure. In another way, a class such as
  9.  *
  10.  * Person
  11.  *
  12.  * <PRE>
  13.  * - flight:Flight = aFlight
  14.  * - personName:String =  aName
  15.  * - bookingNumber: Integer =  aBooking
  16.  * - pos: Pos = aSeat
  17.  * </PRE>
  18.  *
  19.  * equals
  20.  *
  21.  * Profile
  22.  * <PRE>
  23.  * - flight:Flight = aFlight
  24.  * - personNameMask:boolean = true
  25.  * - bookingNumberMask:boolean = true
  26.  * - posMask:boolean = true
  27.  * </PRE>
  28.  *
  29.  * @author Texier Mathieu and Frederic Bidon
  30.  */
  31. public class Profile extends Person {
  32.     /**
  33.      * Construct an empty profile
  34.      */    
  35.     public Profile (){
  36.     }
  37.    
  38.     /**
  39.      * Set the name of the person and unmask the value
  40.      * @param personName name of the person
  41.      * @throws Exception if the invariant _check() is violated
  42.      * @throws NullPointerException if personName is null
  43.      */      
  44.     public void setPersonName (String personName) throws Exception, NullPointerException {
  45.         if (personName == null)
  46.             throw new NullPointerException ("Try to set a mask  with a null value on person Name");
  47.        
  48.         super.setPersonName (personName);
  49.         personNameMask = false;
  50.         _check ();
  51.     }
  52.    
  53.     /**
  54.      * Set the flight and unmask the value
  55.      * @param flight Flight on witch the person has booked.
  56.      * @throws Exception if the invariant _check() is violated
  57.      * @throws NullPointerException if flight is null
  58.      */    
  59.     public void setFlight (Flight flight) throws Exception , NullPointerException{
  60.         if (flight == null)
  61.             throw new NullPointerException ("Try to set a mask  with a null value on Flight");
  62.         super.setFlight (flight);
  63.         flightMask = false;
  64.         _check ();
  65.     }
  66.    
  67.     /**
  68.      * Set the booking number and unmask the value
  69.      * @param bookingNumber the booking number
  70.      * @throws Exception if the invariant _check() is violated
  71.      */    
  72.     public void setBookingNumber (int bookingNumber) throws Exception {
  73.         if (bookingNumber == 0)
  74.             throw new Exception ("Try to set a mask with the value 0 for booking number");
  75.         super.setBookingNumber (bookingNumber);
  76.         bookingNumberMask = false;
  77.         _check ();
  78.     }
  79.    
  80.     /**
  81.      * Set the position and unmask the value
  82.      * @param pos The position of the seat on the <CODE>flight</CODE>
  83.      * @throws Exception if the invariant _check() is violated
  84.      * @throws NullPointerException if pos is null
  85.      */    
  86.     public void setPos (Pos pos) throws Exception, NullPointerException {
  87.         if (pos == null)
  88.             throw new NullPointerException ("Try to set a mask  with a null value on Pos");
  89.         super.setPos (pos);
  90.         posMask = false;
  91.         _check ();
  92.     }
  93.    
  94.     /**
  95.      * Return true if <CODE>personName</CODE> is masked
  96.      * @return the value of the mask on personName
  97.      */    
  98.     public boolean personNameIsMask () {
  99.         return personNameMask;
  100.     }
  101.    
  102.     /**
  103.      * Return true if <CODE>flight</CODE> is masked
  104.      * @return the value of the mask on flight
  105.      */      
  106.     public boolean flightIsMask () {
  107.         return flightMask;
  108.     }
  109.    
  110.     /**
  111.      * Return true if <CODE>bookingNumber</CODE> is masked
  112.      * @return the value of the mask on bookingNumber
  113.      */          
  114.     public boolean bookingNumberIsMask () {
  115.         return bookingNumberMask;
  116.     }
  117.    
  118.     /**
  119.      * Return true if <CODE>pos</CODE> is masked
  120.      * @return the value of the mask on pos
  121.      */      
  122.     public boolean posIsMask () {
  123.         return posMask;
  124.     }
  125.    
  126.      /**
  127.      * Verify invariants :
  128.      <PRE>
  129.      - either the mask is true or the object = null
  130.      </PRE>
  131.      * @throws Exception if the invariant is violated
  132.      */  
  133.     public void _check () throws Exception {
  134.         String errorStr = "is not masked and have null value";
  135.        
  136.         if (!personNameMask && getPersonName () == null) {
  137.             throw new Exception ("Person name" + errorStr) ;
  138.         }
  139.         if (!flightMask && getFlight () == null) {
  140.             throw new Exception ("Flight name" + errorStr) ;
  141.         }
  142.         if (!bookingNumberMask && getBookingNumber () == 0){
  143.             throw new Exception ("Booking number" + errorStr) ;
  144.         }
  145.         if (!posMask && getPos () == null) {
  146.             throw new Exception ("Dimension" + errorStr) ;
  147.         }
  148.     }
  149.    
  150.     /**
  151.      * Overide equals
  152.      * return true if for all fields:
  153.      * person.field. == profile.field || profile.fieldIsMask
  154.      *
  155.      * Where the fields to test are: the name, the flight, the booking number, the seat.
  156.      *
  157.      * The method respects the following conditions: Reflexivity, symmetry, consistency, non-nullity. However, the transitivity in not respected:
  158.      *
  159.      * <PRE>
  160.      * Profile A = new Profile();
  161.      * A.setpersonName(“Person”)
  162.      * Profile B() = new Profile();
  163.      * B.setBookingNumber(1);
  164.      * Person P(personName=“Person”, bookingNumber = 1,…);
  165.      * A.equals(P);  // true
  166.      * B.equals(P);  // true
  167.      * A.equals(B);  // false
  168.      * </PRE>
  169.      *
  170.      * That is why this function of comparison was first named match (). Although the previous properties were not all respected the name of this method have been changed to equals(). The advantage to override this method is that the {@link import java.util.List} interface, called the equals() methods to identify the object on the following functions:
  171.      * <PRE>
  172.      * •      boolean contains(Object o)
  173.      * •      int indexOf(Object o)
  174.      * •      boolean remove(Object o)
  175.      * </PRE>
  176.      * If Object is a Profile, then these methods means respectively: the list match a pattern, return or remove the first element matching a pattern.
  177.      * @return <CODE>true</CODE> if this object is the same as the obj argument or match a {@link  reservation.system.Person} object;
  178.      * <CODE>false</CODE> otherwise
  179.      * @param anObject <CODE>anObject</CODE> - the reference object with which to compare
  180.      */
  181.     public boolean equals (Object anObject) {
  182.         if (anObject != null && anObject instanceof Person) {
  183.             Person person = (Person) anObject;
  184.             return person.equals (this);
  185.         }
  186.         else if (anObject != null && anObject instanceof Profile) {
  187.             Profile profile = (Profile) anObject;
  188.             return (personNameMask == profile.personNameMask)
  189.             && (flightMask == profile.flightMask)
  190.             && (bookingNumberMask == profile.bookingNumberMask)
  191.             && (posMask == profile.posMask)
  192.             && super.equals ( (Person) profile);
  193.         }
  194.         return false;
  195.     }
  196.  
  197.     /**
  198.      * Returns a string representation of this <CODE>Flight</CODE> object. This method
  199.      * is intended to be used only for debugging purposes, and the content and format
  200.      * of the returned string may vary between implementations. The returned string may
  201.      * be empty but may not be <CODE>null</CODE>
  202.      * @return a string representation of this <CODE>Profile</CODE> object.
  203.      */    
  204.     public String toString () {
  205.         String retString = "Profile : \r\n";
  206.         try {
  207.             retString += "personName " + (!personNameMask ? getPersonName ():" masked ");
  208.             retString += "flight " + (!flightMask ? getFlight ().toString ():" masked ");
  209.             retString += "pos " + (!posMask ? getPos ().toString ():" masked ");
  210.             retString += "bookingNumber " + (!bookingNumberMask ? getBookingNumber ()+"" :" masked ")+"\r\n";
  211.         } catch (Exception  e){System.err.println (e);}
  212.         return  retString;
  213.     }
  214.    
  215.     private boolean personNameMask = true;
  216.     private boolean flightMask = true;
  217.     private boolean bookingNumberMask = true;
  218.     private boolean posMask = true;
  219. }

contact - link to this site