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