/*
* Pos.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 Pos structure. This object define the dimention of a {@link reservation.system.Flight} and the seat for a <CODE> {@link reservation.system.Person}</CODE>.
* @author Texier Mathieu and Frederic Bidon
*/
/**
* Construct a <CODE>Pos</CODE> object.
* @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}.
* @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}.
* @throws Exception When value dosn't make sense, this exception is thrown
*/
public Pos
(short row,
short col
) throws Exception {
this.row = row;
this.col = col;
_check ();
}
/**
* 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}.
* @return the row
* @throws Exception when the invariant is violated
*/
_check ();
return row;
}
/**
* 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}.
* @return the col
* @throws Exception when the invariant is violated
*/
_check ();
return col;
}
/**
* 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 Pos) {
Pos pos = (Pos) anObject;
return ((this.row == pos.row) && (this.col == pos.col));
}
else
return false;
}
/**
* 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>Pos</CODE> object.
*/
return "("+row+","+col+")";
}
/**
* Creates and returns a copy of this object.
* @return a copy of this <CODE>Pos</CODE> object
* @throws CloneNotSupportedException if the object's class does not support the <CODE>Cloneable</CODE> interface.
*/
try {
return new Pos (row, col);
}
/**
* Verify invariants :
* <PRE>
* - dimension > 0
* </PRE>
* @throws Exception if the invariant is violated
*/
if (row <= 0 || col <= 0)
throw new Exception ("Position has a negative or null value");
}
private short row;
private short col;
}