summaryrefslogtreecommitdiff
path: root/src/main/java/design/persistence/JSONLeagueDatabase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/design/persistence/JSONLeagueDatabase.java')
-rw-r--r--src/main/java/design/persistence/JSONLeagueDatabase.java21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/main/java/design/persistence/JSONLeagueDatabase.java b/src/main/java/design/persistence/JSONLeagueDatabase.java
index edc649b..795c582 100644
--- a/src/main/java/design/persistence/JSONLeagueDatabase.java
+++ b/src/main/java/design/persistence/JSONLeagueDatabase.java
@@ -13,8 +13,6 @@ import design.model.League;
import java.io.File;
import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -100,18 +98,19 @@ public class JSONLeagueDatabase implements LeagueDatabase {
save();
}
- public File exportData(File newFile) throws IOException{
- Files.copy(file.toPath(), newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
- return newFile;
- }
-
- public void importData(File newFile) throws IOException {
- League[] newLeagues = mapper.readValue(newFile, League[].class);
+ @Override
+ public void importData(JsonNode tree) throws IOException {
+ League[] data = mapper.treeToValue(tree, League[].class);
cache.clear();
- for (League l: newLeagues) {
- cache.put(l.getId(), l);
+ for (League league : data) {
+ cache.put(league.getId(), league);
}
save();
}
+ @Override
+ public JsonNode exportData() {
+ Object[] data = cache.values().toArray();
+ return mapper.valueToTree(data);
+ }
}