cleanup
This commit is contained in:
@@ -10,7 +10,6 @@ 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 {
|
||||
@@ -32,19 +31,19 @@ final class DataRepository {
|
||||
return getInstance().directoryPath;
|
||||
}
|
||||
|
||||
public static void WalkFileSystemTree(final AccomodationManager manager, Path rootDir) throws IOException {
|
||||
public static void WalkFileSystemTree(final AccomodationManager manager, final Path rootDir) throws IOException {
|
||||
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
|
||||
System.out.println("File: " + file.toAbsolutePath());
|
||||
// load account number, and content
|
||||
if (attrs.isRegularFile()) {
|
||||
String namestring = file.getName(file.getNameCount() - 1).toString();
|
||||
final String namestring = file.getName(file.getNameCount() - 1).toString();
|
||||
if (namestring.endsWith("json")) {
|
||||
if (namestring.startsWith("acc")) { // * load Account *//
|
||||
try {
|
||||
manager.load(file);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -55,7 +54,7 @@ final class DataRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) {
|
||||
System.out.println("Directory: " + dir.toAbsolutePath());
|
||||
// prepare to load account number
|
||||
return FileVisitResult.CONTINUE;
|
||||
@@ -63,21 +62,21 @@ final class DataRepository {
|
||||
});
|
||||
}
|
||||
|
||||
public static void LoadAccount(Path file) throws IOException {
|
||||
/**
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public final static Account LoadAccount(final 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);
|
||||
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;
|
||||
Account ac = new Account();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
String.format("Load Account %s", name);
|
||||
final String name = jsonReader.nextName();
|
||||
switch (name) {
|
||||
case "Account":
|
||||
jsonReader.beginObject();
|
||||
ac = new Account();
|
||||
break;
|
||||
case "account_number":
|
||||
ac.setAccount_number(jsonReader.nextString());
|
||||
@@ -90,8 +89,8 @@ final class DataRepository {
|
||||
break;
|
||||
case "Address":
|
||||
jsonReader.beginObject();
|
||||
Address ad = new Address();
|
||||
jsonReader.nextName();
|
||||
ad = new Address();
|
||||
ad.setStreet(jsonReader.nextString());
|
||||
jsonReader.nextName();
|
||||
ad.setCity(jsonReader.nextString());
|
||||
@@ -110,7 +109,9 @@ final class DataRepository {
|
||||
jsonReader.beginObject();
|
||||
break;
|
||||
case "email":
|
||||
ac.setEmail_address(new EmailAddress(jsonReader.nextString()));
|
||||
String s = jsonReader.nextString();
|
||||
s = s != null ? s : "";
|
||||
ac.setEmail_address(new EmailAddress(s));
|
||||
jsonReader.endObject();
|
||||
jsonReader.endObject();
|
||||
break;
|
||||
@@ -122,17 +123,18 @@ final class DataRepository {
|
||||
}
|
||||
}
|
||||
jsonReader.close();
|
||||
return ac.account_number.length() > 8 ? ac : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void loadReservation(JsonReader rdr, Account ac) throws IOException {
|
||||
AccountReservationList reservation_list = new AccountReservationList();
|
||||
static void loadReservation(final JsonReader rdr, final Account ac) throws IOException {
|
||||
final AccountReservationList reservation_list = new AccountReservationList();
|
||||
rdr.beginArray();
|
||||
while (rdr.hasNext()) {
|
||||
rdr.beginObject();
|
||||
String name = rdr.nextName();
|
||||
Reservation rsrv = new HouseReservation(new Address());
|
||||
final Reservation rsrv = new HouseReservation(new Address());
|
||||
rdr.beginObject();
|
||||
name = rdr.nextName();
|
||||
rsrv.reservation_number = rdr.nextString();
|
||||
|
||||
Reference in New Issue
Block a user