update deserialization
This commit is contained in:
@@ -10,6 +10,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
final class DataRepository {
|
||||
@@ -19,7 +20,7 @@ final class DataRepository {
|
||||
private String directoryPath;
|
||||
private static final DataRepository instance = new DataRepository();
|
||||
|
||||
protected static DataRepository getInstance() {
|
||||
protected final static DataRepository getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ final class DataRepository {
|
||||
return getInstance().directoryPath;
|
||||
}
|
||||
|
||||
public static void WalkFileSystemTree(final AccomodationManager manager, Path rootDir) throws IOException{
|
||||
public static void WalkFileSystemTree(final AccomodationManager manager, Path rootDir) throws IOException {
|
||||
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||
@@ -62,8 +63,9 @@ final class DataRepository {
|
||||
});
|
||||
}
|
||||
|
||||
public static void LoadAccount(Path file) throws IOException{
|
||||
/** @TODO finish loading Account */
|
||||
public static void LoadAccount(Path file) throws IOException {
|
||||
/** @TODO finish loading Account */
|
||||
final Gson gson = new Gson();
|
||||
try (BufferedReader in = new BufferedReader(new FileReader(file.toFile(), StandardCharsets.UTF_8))) {
|
||||
JsonReader jsonReader = new JsonReader(in);
|
||||
jsonReader.beginObject();
|
||||
@@ -113,33 +115,7 @@ final class DataRepository {
|
||||
jsonReader.endObject();
|
||||
break;
|
||||
case "reservation_list":
|
||||
jsonReader.beginArray();
|
||||
jsonReader.beginObject();
|
||||
break;
|
||||
case "CabinReservation":
|
||||
jsonReader.beginObject();
|
||||
name = jsonReader.nextName();
|
||||
CabinReservation cabin = new CabinReservation(ad);
|
||||
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(ad);
|
||||
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(ad);
|
||||
hotel.setMailing_address(ad);
|
||||
hotel.setPhysical_address(ad);
|
||||
hotel.reservation_number = jsonReader.nextString();
|
||||
loadReservation(jsonReader, ac);
|
||||
break;
|
||||
default:
|
||||
System.out.println(name);
|
||||
@@ -148,5 +124,22 @@ final class DataRepository {
|
||||
jsonReader.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void loadReservation(JsonReader rdr, Account ac) throws IOException {
|
||||
AccountReservationList reservation_list = new AccountReservationList();
|
||||
rdr.beginArray();
|
||||
while (rdr.hasNext()) {
|
||||
rdr.beginObject();
|
||||
String name = rdr.nextName();
|
||||
Reservation rsrv = new HouseReservation(new Address());
|
||||
rdr.beginObject();
|
||||
name = rdr.nextName();
|
||||
rsrv.reservation_number = rdr.nextString();
|
||||
rdr.endObject();
|
||||
rdr.endObject();
|
||||
reservation_list.add(rsrv);
|
||||
}
|
||||
rdr.endArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user