Modification de repository

This commit is contained in:
Maximilien LEDOUX
2022-03-11 16:54:28 +01:00
parent 8f09dd29b6
commit dd9eb7bd2d
5 changed files with 16 additions and 25 deletions

View File

@@ -1,8 +1,8 @@
package lightcontainer.storage;
public interface Adapter {
String toString();
String toString(AppData appData);
AppData fromString(String appDataString);
}

View File

@@ -9,18 +9,11 @@ import java.util.*;
*/
public class JsonAdapter implements Adapter {
private AppData appData;
public JsonAdapter(AppData appData) {
this.appData = appData;
}
/**
*
* @return A Json String containing AppData properties
*/
@Override
public String toString() {
public String toString(AppData appData) {
return addData(appData);
}
@@ -77,7 +70,6 @@ public class JsonAdapter implements Adapter {
}
/**
*
* @param appDataString The Json String to convert
* @return An AppData instance
*/
@@ -100,8 +92,7 @@ public class JsonAdapter implements Adapter {
for (User user : users) {
appData.addUser(user.getName(), user.getPassword(), user.getAesKey());
}
this.appData = appData;
return this.appData;
return appData;
} catch (JsonParseException parseException) {
System.out.println("[FFE] : Error while loading configuration file"); //TODO - changer en log
return null;

View File

@@ -12,13 +12,15 @@ public class Repository {
private final String filePath;
private final Adapter adapter;
private final AppData appData;
/**
* @param filePath The path to the configuration file
* @param adapter The adapter that converts objects to string and vice-versa
*/
public Repository(String filePath, Adapter adapter) {
public Repository(String filePath, AppData appData, Adapter adapter) {
this.filePath = filePath;
this.appData = appData;
this.adapter = adapter;
}