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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1 @@
|
||||
{
|
||||
"Account": {
|
||||
"account_number": "A1450981765",
|
||||
"phone_number": "701-456-7890",
|
||||
"mailing_address": {
|
||||
"Address": {
|
||||
"street": "10 wilco ave",
|
||||
"city": "wilco",
|
||||
"state": "WY",
|
||||
"zip": "82801"
|
||||
}
|
||||
},
|
||||
"email_address": {
|
||||
"EmailAddress": {
|
||||
"email": "wilco@wyommin.net"
|
||||
}
|
||||
},
|
||||
"reservations": [
|
||||
{
|
||||
"CabinReservation": {
|
||||
"reservation_number": "R0535276622"
|
||||
}
|
||||
},
|
||||
{
|
||||
"HouseReservation": {
|
||||
"reservation_number": "R0499811708"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CabinReservation": {
|
||||
"reservation_number": "R0535276622"
|
||||
}
|
||||
},
|
||||
{
|
||||
"HouseReservation": {
|
||||
"reservation_number": "R0499811708"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
{ "Account":{"account_number": "A1450981765","phone_number": "701-456-7890","mailing_address": { "Address":{"street": "10 wilco ave","city": "wilco","state": "WY","zip": "82801"}},"email_address": { "EmailAddress":{"email": "wilco@wyommin.net"}},"reservations":[{"CabinReservation":{"reservation_number":"R0535276622"}},{"HouseReservation":{"reservation_number":"R0499811708"}},{"CabinReservation":{"reservation_number":"R0535276622"}},{"HouseReservation":{"reservation_number":"R0499811708"}}]}}
|
||||
@@ -1,41 +1 @@
|
||||
{
|
||||
"Account": {
|
||||
"account_number": "A2074212339",
|
||||
"phone_number": "301-356-3890",
|
||||
"mailing_address": {
|
||||
"Address": {
|
||||
"street": "30 Amstadam ave",
|
||||
"city": "New York",
|
||||
"state": "NY",
|
||||
"zip": "12010"
|
||||
}
|
||||
},
|
||||
"email_address": {
|
||||
"EmailAddress": {
|
||||
"email": "newbee952@aol.com"
|
||||
}
|
||||
},
|
||||
"reservations": [
|
||||
{
|
||||
"HotelReservation": {
|
||||
"reservation_number": "R0123087344"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CabinReservation": {
|
||||
"reservation_number": "R2042828431"
|
||||
}
|
||||
},
|
||||
{
|
||||
"HotelReservation": {
|
||||
"reservation_number": "R0123087344"
|
||||
}
|
||||
},
|
||||
{
|
||||
"CabinReservation": {
|
||||
"reservation_number": "R2042828431"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
{ "Account":{"account_number": "A2074212339","phone_number": "301-356-3890","mailing_address": { "Address":{"street": "30 Amstadam ave","city": "New York","state": "NY","zip": "12010"}},"email_address": { "EmailAddress":{"email": "newbee952@aol.com"}},"reservations":[{"HotelReservation":{"reservation_number":"R0123087344"}},{"CabinReservation":{"reservation_number":"R2042828431"}},{"HotelReservation":{"reservation_number":"R0123087344"}},{"CabinReservation":{"reservation_number":"R2042828431"}}]}}
|
||||
Reference in New Issue
Block a user