update
This commit is contained in:
@@ -6,8 +6,8 @@ package lodge.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import lodge.reservation.Reservation;
|
||||
import lodge.reservation.IReservation;
|
||||
import lodge.reservation.Reservation;
|
||||
|
||||
class AccountReservationList extends ArrayList<IReservation> {
|
||||
|
||||
@@ -16,21 +16,24 @@ class AccountReservationList extends ArrayList<IReservation> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean add(final IReservation reservation) throws RuntimeException{
|
||||
public synchronized boolean add(final IReservation reservation) throws RuntimeException {
|
||||
boolean result = true;
|
||||
Reservation rsrv = this.find(reservation.getReservation_number());
|
||||
result = rsrv == null;
|
||||
if( !result ){
|
||||
throw new DuplicateObjectException(String.format("Error No Dups, Reservation exists: %s.", rsrv.getReservation_number()));
|
||||
if (!result) {
|
||||
throw new DuplicateObjectException(
|
||||
String.format("Error No Dups, Reservation exists: %s.", rsrv.getReservation_number()));
|
||||
}
|
||||
result = ((IReservation)reservation).checkValid();
|
||||
|
||||
if(result){
|
||||
((Reservation)reservation).setReservation_number(AccountReservationList.reservationSerial((Reservation)reservation));
|
||||
((Reservation)reservation).setPrice(reservation.calculatePrice());
|
||||
result = ((IReservation) reservation).checkValid();
|
||||
|
||||
if (result) {
|
||||
((Reservation) reservation)
|
||||
.setReservation_number(AccountReservationList.reservationSerial((Reservation) reservation));
|
||||
((Reservation) reservation).setPrice(reservation.calculatePrice());
|
||||
result = super.add(reservation);
|
||||
}else{
|
||||
throw new IllegalArgumentException(String.format("error reservation invalid: %s", ((Reservation)reservation).getReservation_number()));
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("error reservation invalid: %s",
|
||||
((Reservation) reservation).getReservation_number()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -56,9 +59,9 @@ class AccountReservationList extends ArrayList<IReservation> {
|
||||
}
|
||||
|
||||
public Reservation find(String reservation_number) {
|
||||
for(IReservation rsrv: this){
|
||||
if( rsrv.getReservation_number().compareTo(reservation_number) == 0 ){
|
||||
return (Reservation)rsrv;
|
||||
for (IReservation rsrv : this) {
|
||||
if (rsrv.getReservation_number().compareTo(reservation_number) == 0) {
|
||||
return (Reservation) rsrv;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -67,8 +70,8 @@ class AccountReservationList extends ArrayList<IReservation> {
|
||||
public void update(AccountReservationList incoming_reservation_list) {
|
||||
for (IReservation rsrv : incoming_reservation_list) {
|
||||
Reservation onListRsrv = find(rsrv.getReservation_number());
|
||||
if( onListRsrv != null ){
|
||||
onListRsrv.update((Reservation)rsrv);
|
||||
if (onListRsrv != null) {
|
||||
onListRsrv.update((Reservation) rsrv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user