📄 profile.java
字号:
/* * Profile.java * The package system contains the different class allowing to create and to select the object to store in the database. */
package reservation.system;
/**
* 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
*
* Person
*
* <PRE>
* - flight:Flight = aFlight
* - personName:String = aName
* - bookingNumber: Integer = aBooking
* - pos: Pos = aSeat
* </PRE>
*
* equals
*
* Profile
* <PRE>
* - flight:Flight = aFlight
* - personNameMask:boolean = true
* - bookingNumberMask:boolean = true
* - posMask:boolean = true
* </PRE>
*
* @author Texier Mathieu and Frederic Bidon
*/
public class Profile extends Person {
/**
* Construct an empty profile
*/
public Profile (){
}
/**
* Set the name of the person and unmask the value
* @param personName name of the person
* @throws Exception if the invariant _check() is violated
* @throws NullPointerException if personName is null
*/
public void setPersonName (String personName) throws Exception, NullPointerException {
if (personName == null)
throw new NullPointerException ("Try to set a mask with a null value on person Name");
super.setPersonName (personName);
personNameMask = false;
_check ();
}
/**
* Set the flight and unmask the value
* @param flight Flight on witch the person has booked.
* @throws Exception if the invariant _check() is violated
* @throws NullPointerException if flight is null
*/
public void setFlight (Flight flight) throws Exception , NullPointerException{
if (flight == null)
throw new NullPointerException ("Try to set a mask with a null value on Flight");
super.setFlight (flight);
flightMask = false;
_check ();
}
/**
* Set the booking number and unmask the value
* @param bookingNumber the booking number
* @throws Exception if the invariant _check() is violated
*/
public void setBookingNumber (int bookingNumber) throws Exception {
if (bookingNumber == 0)
throw new Exception ("Try to set a mask with the value 0 for booking number");
super.setBookingNumber (bookingNumber);
bookingNumberMask = false;
_check ();
}
/**
* Set the position and unmask the value
* @param pos The position of the seat on the <CODE>flight</CODE>
* @throws Exception if the invariant _check() is violated
* @throws NullPointerException if pos is null
*/
public void setPos (Pos pos) throws Exception, NullPointerException {
if (pos == null)
throw new NullPointerException ("Try to set a mask with a null value on Pos");
super.setPos (pos);
posMask = false;
_check ();
}
/**
* Return true if <CODE>personName</CODE> is masked
* @return the value of the mask on personName
*/
public boolean personNameIsMask () {
return personNameMask;
}
/**
* Return true if <CODE>flight</CODE> is masked
* @return the value of the mask on flight
*/
public boolean flightIsMask () {
return flightMask;
}
/**
* Return true if <CODE>bookingNumber</CODE> is masked
* @return the value of the mask on bookingNumber
*/
public boolean bookingNumberIsMask () {
return bookingNumberMask;
}
/**
* Return true if <CODE>pos</CODE> is masked
* @return the value of the mask on pos
*/
public boolean posIsMask () {
return posMask;
}
/**
* Verify invariants :
<PRE>
- either the mask is true or the object = null
</PRE>
* @throws Exception if the invariant is violated
*/
public void _check () throws Exception {
String errorStr = "is not masked and have null value";
if (!personNameMask && getPersonName () == null) {
throw new Exception ("Person name" + errorStr) ;
}
if (!flightMask && getFlight () == null) {
throw new Exception ("Flight name" + errorStr) ;
}
if (!bookingNumberMask && getBookingNumber () == 0){
throw new Exception ("Booking number" + errorStr) ;
}
if (!posMask && getPos () == null) {
throw new Exception ("Dimension" + errorStr) ;
}
}
/**
* Overide equals
* return true if for all fields:
* person.field. == profile.field || profile.fieldIsMask
*
* Where the fields to test are: the name, the flight, the booking number, the seat.
*
* The method respects the following conditions: Reflexivity, symmetry, consistency, non-nullity. However, the transitivity in not respected:
*
* <PRE>
* Profile A = new Profile();
* A.setpersonName(揚erson
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -