update time function, rebased

This commit is contained in:
2025-09-03 08:56:57 -04:00
parent d022f52060
commit d0a1567fd2
9 changed files with 154 additions and 161 deletions

View File

@@ -1,12 +1,17 @@
package lodge.reservationsystem;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import com.google.gson.stream.JsonReader;
final class DataRepository {
// SINGLETON CLASS
// hard code data store location for storage of
@@ -55,5 +60,93 @@ final class DataRepository {
return FileVisitResult.CONTINUE;
}
});
}
public static void LoadAccount(Path file) throws IOException{
/** @TODO finish loading Account */
try (BufferedReader in = new BufferedReader(new FileReader(file.toFile(), StandardCharsets.UTF_8))) {
JsonReader jsonReader = new JsonReader(in);
jsonReader.beginObject();
Account ac = null;
Address ad = null;
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
System.out.println(String.format("Load Account %s", name));
switch (name) {
case "Account":
jsonReader.beginObject();
ac = new Account();
break;
case "account_number":
ac.setAccount_number(jsonReader.nextString());
break;
case "phone_number":
ac.setPhone_number(jsonReader.nextString());
break;
case "mailing_address":
jsonReader.beginObject();
break;
case "Address":
jsonReader.beginObject();
System.out.println(jsonReader.nextName());
ad = new Address();
ad.setStreet(jsonReader.nextString());
System.out.println(jsonReader.nextName());
ad.setCity(jsonReader.nextString());
System.out.println(jsonReader.nextName());
ad.setState(jsonReader.nextString());
System.out.println(jsonReader.nextName());
ad.setZip(jsonReader.nextString());
jsonReader.endObject();
jsonReader.endObject();
ac.setMailing_address(ad);
break;
case "email_address":
jsonReader.beginObject();
break;
case "EmailAddress":
jsonReader.beginObject();
break;
case "email":
ac.setEmail_address(new EmailAddress(jsonReader.nextString()));
jsonReader.endObject();
jsonReader.endObject();
break;
case "reservation_list":
jsonReader.beginArray();
jsonReader.beginObject();
break;
case "CabinReservation":
jsonReader.beginObject();
name = jsonReader.nextName();
CabinReservation cabin = new CabinReservation();
cabin.setMailing_address(ad);
cabin.setPhysical_address(ad);
cabin.reservation_number = jsonReader.nextString();
break;
case "HouseReservation":
jsonReader.beginObject();
name = jsonReader.nextName();
HouseReservation house = new HouseReservation();
house.setMailing_address(ad);
house.setPhysical_address(ad);
house.reservation_number = jsonReader.nextString();
break;
case "HotelReservation":
jsonReader.beginObject();
name = jsonReader.nextName();
HotelReservation hotel = new HotelReservation();
hotel.setMailing_address(ad);
hotel.setPhysical_address(ad);
hotel.reservation_number = jsonReader.nextString();
break;
default:
System.out.println(name);
}
}
jsonReader.close();
}
}
}