/*
* Flight.java
* The package system contains the different class allowing to create and to select the object to store in the database.
*/
package reservation.system;
import java.io.Serializable;
/**
* This class hold fligth structure. This object could be asserted in the <CODE>FlightList</CODE>.
* @author Texier Mathieu and Frederic Bidon
*/
/**
* The maximum number of rows in a <CODE>flight</CODE>
*/
final static public int ROWS_MAX = 100;
/**
* The maximum number of length of each row in a <CODE>flight</CODE>
*/
final static public int ROW_LENGTH_MAX = 10;
/**
* Construct a <CODE>Flight</CODE> named <CODE>flightName</CODE> with the size <CODE>dimension</CODE>
* @param flightName Name of the flight. This name is used to {@link reservation.system.functions.Lists} the flight
* @param dimension The size of the flight : number of rows and row length
* @throws Exception When value dosn't make sense, this exception is thrown
*/
this.flightName = flightName;
this.dimension = (Pos) dimension.clone ();
_check ();
}
/**
* Return the name of the <CODE>fligth</CODE>
* @return the name of the flight
*/
public String getFlightName
() {
return flightName;
}
/**
* Return the <CODE>dimension</CODE> (Rows and row length) of the <CODE>flight</CODE>
* @return the dimension of the flight
*/
public Pos getDimension () {
return dimension;
}
/**
* Returns a string representation of this <CODE>Flight</CODE> object. This method
* is intended to be used only for debugging purposes, and the content and format
* of the returned string may vary between implementations. The returned string may
* be empty but may not be <CODE>null</CODE>
* @return a string representation of this <CODE>Flight</CODE> object.
*/
return flightName +" "+ dimension;
}
/**
* Overide equals
* @return <CODE>true</CODE> if this object is the same as the obj argument;
* <CODE>false</CODE> otherwise
* @param anObject <CODE>anObject</CODE> - the reference object with which to compare
*/
public boolean equals
(Object anObject
) {
if (anObject != null && anObject instanceof Flight) {
Flight flight = (Flight) anObject;
return (flightName.equals (flight.flightName) && dimension.equals (flight.dimension));
}
else
return false;
}
/**
* Creates and returns a copy of this object.
* @return a copy of this <CODE>Flight</CODE> object
* @throws CloneNotSupportedException if the object's class does not support the <CODE>Cloneable</CODE> interface.
*/
try {
_check ();
return new Flight (flightName, dimension);
}
/**
* Verify invariants :
* <PRE>
* - <CODE>regex</CODE> [[A-Z]*[a-z]*[0-9]*]+<BR>
* - dimension < (<CODE>ROWS_MAX</CODE>,<CODE>ROWS_LENGHT_MAX</CODE>) and > 0
* </PRE>
* @throws NullPointerException if pos or name is null
* @throws Exception if the invariant is violated
*/
if (flightName == null || dimension == null)
if (dimension.getRow () < 1 || dimension.getRow () > ROWS_MAX
|| dimension.getCol () < 1 || dimension.getCol () > ROW_LENGTH_MAX
)
if (!flightName.matches ("[[A-Z]*[a-z]*[0-9]*]+"))
throw new Exception ("The flight name : " + flightName
+ " has illegal character") ;
}
private Pos dimension;
}