diff --git a/src/java/lodge/TestReservations.java b/src/java/lodge/TestReservations.java index 6dd697a..57a6328 100644 --- a/src/java/lodge/TestReservations.java +++ b/src/java/lodge/TestReservations.java @@ -83,7 +83,7 @@ public final class TestReservations { try { mgr.addReservation(acct, cabin); - mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number())); + mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number())); } catch (DuplicateObjectException e) { System.out.println(e.getMessage()); } @@ -94,12 +94,12 @@ public final class TestReservations { // 6. Complete reservation that is associated with an account rsrv = mgr.retreiveReservation(rsrv.getReservation_number()); rsrv.Change(rsrv, ReservationStatusEnum.Completed); - mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number())); + mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number())); // 7. Cancel reservation that is associated with an account rsrv = mgr.retreiveReservation(rsrv.getReservation_number()); rsrv.Change(rsrv, ReservationStatusEnum.Canceled); - mgr.UpdateAccount(mgr.retrieveAccount(acct.account_number())); + mgr.UpdateAccount(mgr.retrieveAccount(acct.getAccount_number())); /* * * if (rsrv != null) { diff --git a/src/java/lodge/reservationsystem/AccomodationManager.java b/src/java/lodge/reservationsystem/AccomodationManager.java index 2420d3f..475c529 100644 --- a/src/java/lodge/reservationsystem/AccomodationManager.java +++ b/src/java/lodge/reservationsystem/AccomodationManager.java @@ -74,15 +74,13 @@ public final class AccomodationManager { return result; } - public Reservation retreiveReservation(String reservation_number) { + public final Reservation retreiveReservation(String reservation_number) { + Reservation rsrv = null; for (Account acct : account_list) { - for (Reservation rsv : acct.reservation_list) { - if (rsv.getReservation_number().compareTo(reservation_number)==0) { - return rsv; - } - } + rsrv = acct.findReservation(reservation_number); + if( rsrv!=null ) break; } - return null; + return rsrv; } } \ No newline at end of file diff --git a/src/java/lodge/reservationsystem/Account.java b/src/java/lodge/reservationsystem/Account.java index 50af596..d9c1e98 100644 --- a/src/java/lodge/reservationsystem/Account.java +++ b/src/java/lodge/reservationsystem/Account.java @@ -8,12 +8,11 @@ import java.nio.file.Path; import java.nio.file.Paths; public class Account { - String account_number = "-99"; - String phone_number; - Address mailing_address; - EmailAddress email_address; + private String account_number = "-99"; + private String phone_number; + private Address mailing_address; + private EmailAddress email_address; - @SuppressWarnings("unused") protected Account() { } @@ -29,9 +28,9 @@ public class Account { this.email_address = email_address; } - AccountReservationList reservation_list = new AccountReservationList();; + private final AccountReservationList reservation_list = new AccountReservationList();; - public AccountReservationList getReservation_list() { + public final AccountReservationList getReservation_list() { return reservation_list; } @@ -85,7 +84,7 @@ public class Account { } } - public String account_number() { + public String getAccount_number() { return account_number; } @@ -93,7 +92,7 @@ public class Account { this.account_number = account_number; } - public String phone_number() { + public String getPhone_number() { return phone_number; } @@ -101,7 +100,7 @@ public class Account { this.phone_number = phone_number; } - public Address mailing_address() { + public Address getMailing_address() { return mailing_address; } @@ -109,7 +108,7 @@ public class Account { this.mailing_address = mailing_address; } - public EmailAddress email_address() { + public EmailAddress getEmail_address() { return email_address; } @@ -125,6 +124,10 @@ public class Account { return result; } + public Reservation findReservation(String reservation_number) { + return this.reservation_list.find(reservation_number); + } + @Override public boolean equals(Object obj) { if (this == obj) @@ -148,4 +151,5 @@ public class Account { this.setMailing_address(acct.mailing_address); this.getReservation_list().update(acct.getReservation_list()); } + } \ No newline at end of file diff --git a/src/java/lodge/reservationsystem/AccountList.java b/src/java/lodge/reservationsystem/AccountList.java index a34d916..47aa158 100644 --- a/src/java/lodge/reservationsystem/AccountList.java +++ b/src/java/lodge/reservationsystem/AccountList.java @@ -29,9 +29,9 @@ public class AccountList extends ArrayList { throws DuplicateObjectException { try { for (Account acct : this) { - if (acct.account_number().compareTo(account.account_number()) == 0) { + if (acct.getAccount_number().compareTo(account.getAccount_number()) == 0) { throw new DuplicateObjectException( - String.format("Account %s exists, duplicates not allowed.", acct.account_number())); + String.format("Account %s exists, duplicates not allowed.", acct.getAccount_number())); } } } catch (DuplicateObjectException e) { @@ -51,7 +51,7 @@ public class AccountList extends ArrayList { // ** Find account return null not-existing. */ public final Account find(String account_number) { for (Account acct : this) { - if (acct.account_number().compareTo(account_number) == 0) { + if (acct.getAccount_number().compareTo(account_number) == 0) { return acct; } } diff --git a/src/java/lodge/reservationsystem/AccountReservationList.java b/src/java/lodge/reservationsystem/AccountReservationList.java index 761d91e..8a46c93 100644 --- a/src/java/lodge/reservationsystem/AccountReservationList.java +++ b/src/java/lodge/reservationsystem/AccountReservationList.java @@ -8,6 +8,7 @@ public class AccountReservationList extends ArrayList { return String.format("R%010d", Math.abs(java.util.Objects.hash(reservation.physical_address))); } + @Override public boolean add(final Reservation reservation) { boolean result = true; try { @@ -45,15 +46,6 @@ public class AccountReservationList extends ArrayList { return sb.toString(); } - public void update(AccountReservationList incoming_reservation_list) { - for (Reservation rsrv : incoming_reservation_list) { - Reservation onListRsrv = find(rsrv.getReservation_number()); - if( onListRsrv != null ){ - onListRsrv.update(rsrv); - } - } - } - public Reservation find(String reservation_number) { for(Reservation rsrv: this){ if( rsrv.getReservation_number().compareTo(reservation_number) == 0 ){ @@ -62,4 +54,13 @@ public class AccountReservationList extends ArrayList { } return null; } + + public void update(AccountReservationList incoming_reservation_list) { + for (Reservation rsrv : incoming_reservation_list) { + Reservation onListRsrv = find(rsrv.getReservation_number()); + if( onListRsrv != null ){ + onListRsrv.update(rsrv); + } + } + } } diff --git a/src/java/lodge/reservationsystem/DataRepository.java b/src/java/lodge/reservationsystem/DataRepository.java index ec64698..bef1be9 100644 --- a/src/java/lodge/reservationsystem/DataRepository.java +++ b/src/java/lodge/reservationsystem/DataRepository.java @@ -121,7 +121,7 @@ final class DataRepository { } } jsonReader.close(); - return ac.account_number.length() > 8 ? ac : null; + return ac.getAccount_number().length() > 8 ? ac : null; } } @@ -133,14 +133,14 @@ final class DataRepository { rdr.beginObject(); rdr.nextName(); String reservationNumber = rdr.nextString(); - loadReservation(ac.reservation_list, reservationType, reservationNumber); + loadReservation(ac, reservationType, reservationNumber); rdr.endObject(); rdr.endObject(); } rdr.endArray(); } - private static void loadReservation(AccountReservationList reservation_list, String reservationType, + private static void loadReservation(Account ac, String reservationType, String reservationNumber) throws IOException { String filename = String.format("rsv-%s.json", reservationNumber); Path basePath = Paths.get(getPath()); @@ -242,9 +242,8 @@ final class DataRepository { } } - if (rsrv.checkValid()) { - reservation_list.add(rsrv); - } + ac.add(rsrv); + } catch (Exception e) { System.out.println(e.toString()); }