📄 flight.java
字号:
/* * 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 */public class Flight extends Object implements Cloneable, Serializable{ /** * 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 */ public Flight (String flightName, Pos dimension) throws Exception{ 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. */ public String toString () { 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. */ protected Object clone () throws CloneNotSupportedException { try { _check (); return new Flight (flightName, dimension); } catch ( Exception e) {System.err.println (e);return null;} } /** * 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 */ public void _check () throws Exception, NullPointerException{ if (flightName == null || dimension == null) throw new NullPointerException ("The flight "+ this +" has an null value.") ; if (dimension.getRow () < 1 || dimension.getRow () > ROWS_MAX || dimension.getCol () < 1 || dimension.getCol () > ROW_LENGTH_MAX ) throw new NullPointerException ("The flight "+ this +" has an out of range value.") ; if (!flightName.matches ("[[A-Z]*[a-z]*[0-9]*]+")) throw new Exception ("The flight name : " + flightName + " has illegal character") ; } private String flightName; private Pos dimension;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -