This commit is contained in:
@@ -18,8 +18,17 @@ import sudoku.structure.Cell;
|
|||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
import sudoku.structure.Sudoku;
|
import sudoku.structure.Sudoku;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe permettant d'effectuer des opérations sur les sudokus afin de les
|
||||||
|
* charger/sauvegarder
|
||||||
|
*/
|
||||||
public class SudokuSerializer {
|
public class SudokuSerializer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convertit un sudoku en object JSON
|
||||||
|
* @param multidoku le sudoku à sérialiser
|
||||||
|
* @return le JSON
|
||||||
|
*/
|
||||||
public static JSONObject serializeSudoku(final MultiDoku multidoku) {
|
public static JSONObject serializeSudoku(final MultiDoku multidoku) {
|
||||||
List<Cell> cellIds = new ArrayList<>();
|
List<Cell> cellIds = new ArrayList<>();
|
||||||
List<Block> blockIds = new ArrayList<>();
|
List<Block> blockIds = new ArrayList<>();
|
||||||
@@ -127,6 +136,9 @@ public class SudokuSerializer {
|
|||||||
return jsonRoot;
|
return jsonRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée le répertoire save afin d'y sauvegarder les sudokus
|
||||||
|
*/
|
||||||
private static void createSaveDir() {
|
private static void createSaveDir() {
|
||||||
File f = new File("save");
|
File f = new File("save");
|
||||||
f.mkdir();
|
f.mkdir();
|
||||||
@@ -202,11 +214,21 @@ public class SudokuSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit un sudoku à partir d'un String en JSON
|
||||||
|
* @param json le sudoku sérialisé
|
||||||
|
* @return le sudoku désérialisé
|
||||||
|
*/
|
||||||
public static MultiDoku deserializeSudoku(final String json) {
|
public static MultiDoku deserializeSudoku(final String json) {
|
||||||
JSONObject jsonRoot = new JSONObject(json);
|
JSONObject jsonRoot = new JSONObject(json);
|
||||||
return deserializeSudoku(jsonRoot);
|
return deserializeSudoku(jsonRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Désérialise un sudoku d'un objet JSON
|
||||||
|
* @param jsonObject l'objet à désérialiser
|
||||||
|
* @return le sudoku correspondant
|
||||||
|
*/
|
||||||
public static MultiDoku deserializeSudoku(final JSONObject jsonObject) {
|
public static MultiDoku deserializeSudoku(final JSONObject jsonObject) {
|
||||||
|
|
||||||
List<Cell> cells = new ArrayList<>();
|
List<Cell> cells = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user