Storage : optimisation des imports et ajout de commentaires
This commit is contained in:
parent
4fbe6bb88c
commit
f9c4ee71b2
@ -1,8 +1,7 @@
|
||||
package lightcontainer.storage;
|
||||
|
||||
public interface Adapter {
|
||||
|
||||
|
||||
|
||||
String toString();
|
||||
|
||||
AppData fromString(String appDataString);
|
||||
|
@ -3,6 +3,9 @@ package lightcontainer.storage;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* File represents all information related to a file
|
||||
*/
|
||||
public class File {
|
||||
|
||||
private final String name;
|
||||
|
@ -4,6 +4,9 @@ import com.google.gson.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Specific implementation of Adapter that converts AppData to Json and vice-versa
|
||||
*/
|
||||
public class JsonAdapter implements Adapter {
|
||||
|
||||
private AppData appData;
|
||||
@ -12,6 +15,10 @@ public class JsonAdapter implements Adapter {
|
||||
this.appData = appData;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return A Json String containing AppData properties
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return addData(appData);
|
||||
@ -69,6 +76,11 @@ public class JsonAdapter implements Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appDataString The Json String to convert
|
||||
* @return An AppData instance
|
||||
*/
|
||||
@Override
|
||||
public AppData fromString(String appDataString) {
|
||||
try {
|
||||
|
@ -10,6 +10,10 @@ import java.nio.file.StandardOpenOption;
|
||||
|
||||
public class Repository {
|
||||
|
||||
/**
|
||||
* @param filePath The path where the file must be saved
|
||||
* @param adapter The service that converts Objects to Strings
|
||||
*/
|
||||
static void save(String filePath, Adapter adapter) {
|
||||
if (filePath != null) {
|
||||
String jsonAppData = adapter.toString();
|
||||
@ -22,6 +26,11 @@ public class Repository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePath The path where the file is stored
|
||||
* @param adapter The service that converts Strings to objects
|
||||
* @return
|
||||
*/
|
||||
static AppData load(String filePath, Adapter adapter) {
|
||||
String jsonString = readFile(filePath);
|
||||
return adapter.fromString(jsonString);
|
||||
|
@ -1,9 +1,7 @@
|
||||
package lightcontainer.storage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User represents a user of the system.
|
||||
|
Loading…
Reference in New Issue
Block a user