As with the RoomListDB class, code methods separately, then test immediately. Make sure that you add more entries into the CustomerListDBTest’s setup method, into the custs array. Beware: the file must remain in sorted order!
The fields and constructor signatures:
private List database;
private final ListPersistenceObject listPersistenceObject;
private final HotelFactory factory;
public CustomerListDB (ListPersistenceObject listPersistenceObject)
public CustomerListDB (ListPersistenceObject listPersistenceObject,
HotelFactory factory)
• code the constructors. The listPersistenceObject field, once set by the constructor is to be used to assign a reference to the database. The factory field must be assigned the value referenced by a HotelFactory or to the value referenced by the factory parameter specified in the two parameter constructor’s parameter list. Recall that final fields must be assigned a value prior to the termination of the constructor. Although the database field is not final, you must not provide a setter method. The reason that it is not final is because we want to be able to assign it the null value after the list has been persisted to disk in the disconnect method.
• Override the toString method and test. toString returns a String representation of the contents of the database, one element per line as shown by the sample below. The first line must be a message indicating the number of elements in the database. Use StringBuilder for efficiency.
Number of customers in database: 8
raj@king.ruRajWongvisa4556737586899855
joe.mancini@mail.meJoeMancini**
Etc.
• Override and test the add(Customer cust) method
Adds a customer object to the database. Add a reference to a copy of the object referenced by the cust and not the actual object being referenced by the parameter since we are using an internal list as the database. In order to instantiate a Customer object, use the factory class. The method must throw a DuplicateCustomerException if the specified email address is already in the database. Note that the customer must be added in email order to keep the database in sorted order. Implement a binary search private method to help. Verify that add works by invoking toString.
• Override and test the disconnect method
In order to make the database transactions persistent, the disconnect method must be implemented. This method must save the database to disk and assign null to the database field.
In your test method, after checking that add works, next make certain that the changes to the database are persistent (i.e. add new customers to the list, invoke the disconnect method to persist the customers, reconnect by creating a new instance of the CustomerListDB class and display the string returned by the toString() method to ensure that the new customers appear in the list in the correct locations). Do NOT invoke the teardown method until you have reconnected!
• Override the getCustomer(Email email) method
Returns a reference to the Customer with the given email address, or throws a NonExistingCustomerException if none can be found. Use the binary search private method that you implemented, since the database is sorted.
• Override the update (Email email, CreditCard card) method
Updates a customer in the database if the customer exists. If there is no matching customer, a NonExistingCustomerException must be thrown. Make sure that the changes to the database are persistent.
As with the RoomListDB class, code methods separately, then test immediately. Make sure that you add more entries into the CustomerListDBTest’s setup method, into the custs array. Beware: the file must remain in sorted order!
The fields and constructor signatures: private List database;
private final ListPersistenceObject listPersistenceObject;
private final HotelFactory factory;
• code the constructors. The listPersistenceObject field, once set by the constructor is to be used to assign a reference to the database. The factory field must be assigned the value referenced by a HotelFactory or to the value referenced by the factory parameter specified in the two parameter constructor’s parameter list. Recall that final fields must be assigned a value prior to the termination of the constructor. Although the database field is not final, you must not provide a setter method. The reason that it is not final is because we want to be able to assign it the null value after the list has been persisted to disk in the disconnect method.
• Override the toString method and test. toString returns a String representation of the contents of the database, one element per line as shown by the sample below. The first line must be a message indicating the number of elements in the database. Use StringBuilder for efficiency.
Number of customers in database: 8 raj@king.ruRajWongvisa4556737586899855 joe.mancini@mail.meJoeMancini** Etc.
• Override and test the add(Customer cust) method
Adds a customer object to the database. Add a reference to a copy of the object referenced by the cust and not the actual object being referenced by the parameter since we are using an internal list as the database. In order to instantiate a Customer object, use the factory class. The method must throw a DuplicateCustomerException if the specified email address is already in the database. Note that the customer must be added in email order to keep the database in sorted order. Implement a binary search private method to help. Verify that add works by invoking toString.
• Override and test the disconnect method
In order to make the database transactions persistent, the disconnect method must be implemented. This method must save the database to disk and assign null to the database field.
In your test method, after checking that add works, next make certain that the changes to the database are persistent (i.e. add new customers to the list, invoke the disconnect method to persist the customers, reconnect by creating a new instance of the CustomerListDB class and display the string returned by the toString() method to ensure that the new customers appear in the list in the correct locations). Do NOT invoke the teardown method until you have reconnected!
• Override the getCustomer(Email email) method
Returns a reference to the Customer with the given email address, or throws a NonExistingCustomerException if none can be found. Use the binary search private method that you implemented, since the database is sorted.
• Override the update (Email email, CreditCard card) method
Updates a customer in the database if the customer exists. If there is no matching customer, a NonExistingCustomerException must be thrown. Make sure that the changes to the database are persistent.