|
@@ -20,560 +20,500 @@ import java.util.HashMap;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.zip.ZipException;
|
|
|
|
|
|
/**
|
|
|
* Controller for the Loading.
|
|
|
- *
|
|
|
+ *
|
|
|
* @author Gruppe14
|
|
|
*/
|
|
|
public class LoadController {
|
|
|
- private Model model;
|
|
|
- private CategoryController cgC;
|
|
|
- private CanvasController cvsC;
|
|
|
- private ObjectController objC;
|
|
|
- private NodeController uppC;
|
|
|
- private MultiPurposeController mpC;
|
|
|
- private JsonParser parser;
|
|
|
- /**
|
|
|
- * Constructor.
|
|
|
- *
|
|
|
- * @param model
|
|
|
- * Model
|
|
|
- * @param cg
|
|
|
- * CategoryController
|
|
|
- * @param cvs
|
|
|
- * CanvasController
|
|
|
- * @param obj
|
|
|
- * ObjectController
|
|
|
- * @param mp
|
|
|
- * MultiPurposeController
|
|
|
- */
|
|
|
- public LoadController(Model model, CategoryController cg, CanvasController cvs, ObjectController obj,
|
|
|
- NodeController uppC, MultiPurposeController mp) {
|
|
|
- this.model = model;
|
|
|
- this.cgC = cg;
|
|
|
- this.cvsC = cvs;
|
|
|
- this.objC = obj;
|
|
|
- this.uppC = uppC;
|
|
|
- this.mpC = mp;
|
|
|
- this.parser = new JsonParser();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Reads the the JSON File and load the state into the Model.
|
|
|
- *
|
|
|
- * @param path
|
|
|
- * the Path
|
|
|
- * @throws IOException
|
|
|
- * exception
|
|
|
- */
|
|
|
- public void readSave(String path) throws IOException, ArchiveException, ZipException {
|
|
|
-
|
|
|
- File src = new File(path);
|
|
|
- File folder = readArchive(path, src);
|
|
|
- folder.deleteOnExit();
|
|
|
- String trim = folder.getPath().substring(0,
|
|
|
- folder.getPath().lastIndexOf(folder.getName()) + folder.getName().length());
|
|
|
-
|
|
|
- forwardFiles(folder, trim);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void readJson(String path) throws IOException {
|
|
|
- JsonObject json = (JsonObject) parser.parse(new FileReader(path));
|
|
|
- // get all keys via stream
|
|
|
- List<String> keys = getKeys(json);
|
|
|
- List<String> edges = keys.stream().filter(key -> key.contains("EDGE"))
|
|
|
- .collect(Collectors.toCollection(ArrayList::new));
|
|
|
-
|
|
|
- HashMap<Integer, AbstractCpsObject> objDispatch = new HashMap<>();
|
|
|
- HashMap<Integer, HolonElement> eleDispatch = new HashMap<>();
|
|
|
-
|
|
|
- initialize(keys, json);
|
|
|
- forwardObjects(keys, json, objDispatch, eleDispatch);
|
|
|
- forwardEdges(edges, json, objDispatch);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Loads the Files from the Savefile
|
|
|
- *
|
|
|
- * @param folder
|
|
|
- * @param trim
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- private void forwardFiles(File folder, String trim) throws IOException {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- for (File file : folder.listFiles()) {
|
|
|
- File dst = new File(
|
|
|
- System.getProperty("user.home") + "/.config/HolonGUI/" + file.getPath().replace(trim, ""));
|
|
|
-
|
|
|
- if (file.getName().contains(".json"))
|
|
|
- readJson(file.getPath());
|
|
|
- else if (file.isDirectory())
|
|
|
- forwardFiles(file, trim);
|
|
|
- else {
|
|
|
- dst.getParentFile().mkdirs();
|
|
|
- Files.copy(file.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * distribute the Edges
|
|
|
- *
|
|
|
- * @param edges
|
|
|
- * @param json
|
|
|
- * @param objDispatch
|
|
|
- */
|
|
|
- private void forwardEdges(List<String> edges, JsonObject json, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
- List<String> conn = new ArrayList<>();
|
|
|
-
|
|
|
- for (String edge : edges) {
|
|
|
- if (edge.contains("CVSEDGE"))
|
|
|
- loadEdge(EDGETYPE.CANVAS, json.get(edge), objDispatch);
|
|
|
- if (edge.contains("CONNEDGE"))
|
|
|
- conn.add(edge);
|
|
|
- if (edge.contains("NODE"))
|
|
|
- loadEdge(EDGETYPE.NODE, json.get(edge), objDispatch);
|
|
|
- if (edge.contains("OLD"))
|
|
|
- loadEdge(EDGETYPE.OLD, json.get(edge), objDispatch);
|
|
|
- }
|
|
|
-
|
|
|
- for (String edge : conn) {
|
|
|
- loadEdge(EDGETYPE.CONNECTION, json.get(edge), objDispatch);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Distribute the given keys for right processing
|
|
|
- *
|
|
|
- * @param keys
|
|
|
- * @param json
|
|
|
- * @param objDispatch
|
|
|
- * @param eleDispatch
|
|
|
- */
|
|
|
- private void forwardObjects(List<String> keys, JsonObject json, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
- HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- for (String key : keys) {
|
|
|
- if (key.contains("CATEGORY"))
|
|
|
- loadCategory(json.get(key));
|
|
|
- if (key.contains("CGOBJECT"))
|
|
|
- loadCategoryObject(json.get(key));
|
|
|
- if (key.contains("CGELEMENT"))
|
|
|
- loadCategoryElements(json.get(key));
|
|
|
- if (key.contains("CVSOBJECT"))
|
|
|
- loadCanvasObject(json.get(key), objDispatch);
|
|
|
- if (key.contains("CVSELEMENT"))
|
|
|
- loadCanvasElements(json.get(key), objDispatch, eleDispatch);
|
|
|
- if (key.contains("SWUNITGRAPH"))
|
|
|
- loadUnitGraph(GRAPHTYPE.SWITCH, json.get(key), objDispatch, null);
|
|
|
- if (key.contains("ELEUNITGRAPH"))
|
|
|
- loadUnitGraph(GRAPHTYPE.ELEMENT, json.get(key), null, eleDispatch);
|
|
|
- if (key.contains("TRACKED"))
|
|
|
- loadTracked(json.get(key), objDispatch);
|
|
|
- if (key.contains("STATSGRAPH"))
|
|
|
- loadStatisticGraph(json.get(key), objDispatch);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Init the Global Parameters
|
|
|
- *
|
|
|
- * @param keys
|
|
|
- * @param json
|
|
|
- */
|
|
|
- private void initialize(List<String> keys, JsonObject json) {
|
|
|
-
|
|
|
- switch (MODE.valueOf(json.get("MODE").getAsString())) {
|
|
|
- case COMPLETE:
|
|
|
- model.setCvsObjIdx(new HashMap<Integer, Integer>());
|
|
|
- model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
|
|
|
- model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
|
|
|
- model.setTrackingObj(new ArrayList<>());
|
|
|
- model.setStatisticData(new ArrayList<>());
|
|
|
- model.setHashcodeMap(new HashMap<>());
|
|
|
- model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
|
|
|
- model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
|
|
|
- IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
|
|
|
- IdCounterElem.setCounter(json.get("IDCOUNTERELEMENT").getAsInt());
|
|
|
- break;
|
|
|
- case PARTIAL:
|
|
|
- model.setCvsObjIdx(new HashMap<Integer, Integer>());
|
|
|
- model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
|
|
|
- model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
|
|
|
- model.setHashcodeMap(new HashMap<>());
|
|
|
- model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
|
|
|
- model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
|
|
|
- IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
|
|
|
- IdCounterElem.setCounter(json.get("IDCOUNTERELEMENT").getAsInt());
|
|
|
- break;
|
|
|
- case CATEGORY:
|
|
|
- model.setCgIdx(new HashMap<String, Integer>());
|
|
|
- model.setCategories(new ArrayList<Category>());
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load a given Category
|
|
|
- *
|
|
|
- * @param jsonElement
|
|
|
- */
|
|
|
- private void loadCategory(JsonElement jsonElement) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- if (mpC.searchCat(jsonElement.getAsString()) == null)
|
|
|
- cgC.addCategory(new Category(jsonElement.getAsString()));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load a given Object in Category by Deserialization
|
|
|
- *
|
|
|
- * @param jsonElement
|
|
|
- */
|
|
|
- private void loadCategoryObject(JsonElement jsonElement) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
- AbstractCpsObject temp = model.getGson().fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
|
|
|
- temp.setImage(checkOS(temp.getImage()));
|
|
|
- initObjects(temp);
|
|
|
- if (mpC.searchCatObj(mpC.searchCat(temp.getSav()), temp.getObjName()) != null)
|
|
|
- cgC.deleteObject(temp.getSav(), temp.getObjName());
|
|
|
- cgC.addObject(mpC.searchCat(temp.getSav()), temp);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load a given Element in Category by Deserialization
|
|
|
- *
|
|
|
- * @param jsonElement
|
|
|
- */
|
|
|
- private void loadCategoryElements(JsonElement jsonElement) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- HolonElement temp = model.getGson().fromJson(jsonElement.getAsJsonObject().get("properties").getAsJsonObject(),
|
|
|
- HolonElement.class);
|
|
|
- initElements(temp);
|
|
|
- objC.addElementIntoCategoryObject(temp.getSaving().getKey(), temp.getSaving().getValue(), temp);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load a given Object in Canvas by Deserialization
|
|
|
- *
|
|
|
- * @param jsonElement
|
|
|
- * @param objDispatch
|
|
|
- */
|
|
|
- private void loadCanvasObject(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- AbstractCpsObject temp = model.getGson().fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
|
|
|
- initObjects(temp);
|
|
|
- temp.setImage(checkOS(temp.getImage()));
|
|
|
- if (temp instanceof CpsUpperNode) {
|
|
|
- model.getHashcodeMap().put(jsonElement.getAsJsonObject().get("hash").getAsInt(), (CpsUpperNode) temp);
|
|
|
- ((CpsUpperNode) temp).setLeftBorder(jsonElement.getAsJsonObject().get("properties").getAsJsonObject().get("leftBorder").getAsInt());
|
|
|
- }
|
|
|
- // if its stored before on the canvas just put it there
|
|
|
- if (temp.getSav().equals("CVS")) {
|
|
|
- cvsC.addObject(temp);
|
|
|
-
|
|
|
- } else {
|
|
|
- // else look up the table and put it into the right Uppernode
|
|
|
- CpsUpperNode temp2 = (CpsUpperNode) objDispatch.get(Integer.parseInt(temp.getSav()));
|
|
|
- uppC.addObjectInUpperNode(temp, temp2);
|
|
|
- }
|
|
|
-
|
|
|
- objDispatch.put(temp.getId(), temp);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load a given Element in Canvas by Deserialization
|
|
|
- *
|
|
|
- * @param jsonElement
|
|
|
- * @param objDispatch
|
|
|
- * @param eleDispatch
|
|
|
- */
|
|
|
- private void loadCanvasElements(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
- HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
- JsonObject object = jsonElement.getAsJsonObject();
|
|
|
-
|
|
|
- HolonElement temp = model.getGson().fromJson(object.get("properties"), HolonElement.class);
|
|
|
- initElements(temp);
|
|
|
- // id which Object it was stored before
|
|
|
- int stored = object.get("ID").getAsInt();
|
|
|
- // lookup that object
|
|
|
- HolonObject temp2 = (HolonObject) objDispatch.get(stored);
|
|
|
- // add it
|
|
|
- objC.addElement(temp2, temp);
|
|
|
- // store element also inside a table
|
|
|
- eleDispatch.put(temp.getId(), temp);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load a given Edge by Deserialization
|
|
|
- *
|
|
|
- * @param type
|
|
|
- * @param jsonElement
|
|
|
- * @param objDispatch
|
|
|
- */
|
|
|
- private void loadEdge(EDGETYPE type, JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- JsonObject object = jsonElement.getAsJsonObject();
|
|
|
- CpsEdge temp = model.getGson().fromJson(object.get("properties"), CpsEdge.class);
|
|
|
- initCpsEdge(temp);
|
|
|
- // look for A and B inside the Table
|
|
|
- temp.setA(objDispatch.get(object.get("A").getAsInt()));
|
|
|
- temp.setB(objDispatch.get(object.get("B").getAsInt()));
|
|
|
-
|
|
|
- int sav = 0;
|
|
|
-
|
|
|
- switch (type) {
|
|
|
- case CANVAS:
|
|
|
- // if in canvas add it into the canvas but delete connection before
|
|
|
- model.getEdgesOnCanvas().add(temp);
|
|
|
- break;
|
|
|
- case CONNECTION:
|
|
|
- // if no duplicates in connection store them into the given A and B
|
|
|
- if (!uppC.lookforDuplicates(temp.getA(), temp.getB(), temp.getA().getConnections()))
|
|
|
- temp.getA().getConnections().add(temp);
|
|
|
- if (!uppC.lookforDuplicates(temp.getA(), temp.getB(), temp.getB().getConnections()))
|
|
|
- temp.getB().getConnections().add(temp);
|
|
|
- break;
|
|
|
- case NODE:
|
|
|
- // put it into given nodeofnode
|
|
|
- sav = object.get("ID").getAsInt();
|
|
|
- ((CpsUpperNode) objDispatch.get(sav)).getNodeEdges().add(temp);
|
|
|
- break;
|
|
|
- case OLD:
|
|
|
- // same as above
|
|
|
- sav = object.get("ID").getAsInt();
|
|
|
- ((CpsUpperNode) objDispatch.get(sav)).getOldEdges().add(temp);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (object.get("connection").getAsBoolean() && !type.equals(EDGETYPE.CONNECTION)) {
|
|
|
- temp.getA().getConnections().add(temp);
|
|
|
- temp.getB().getConnections().add(temp);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Load a Unitgraph by Deserialization
|
|
|
- *
|
|
|
- * @param type
|
|
|
- * @param jsonElement
|
|
|
- * @param objDispatch
|
|
|
- * @param eleDispatch
|
|
|
- */
|
|
|
- private void loadUnitGraph(GRAPHTYPE type, JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
- HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
- JsonObject object = jsonElement.getAsJsonObject();
|
|
|
- List<String> keys = getKeys(object);
|
|
|
- String p = null;
|
|
|
- int mid, x, y = 0;
|
|
|
-
|
|
|
- LinkedList<Point> graphpoint = new LinkedList<>();
|
|
|
- int sav = 0;
|
|
|
- // foreach Point in the graph restore it
|
|
|
- for (String k : keys) {
|
|
|
- if (!k.equals("ID")) {
|
|
|
- p = object.get(k).getAsString();
|
|
|
- mid = p.indexOf(':');
|
|
|
- x = Integer.parseInt(p.substring(0, mid));
|
|
|
- y = Integer.parseInt(p.substring(mid + 1, p.length()));
|
|
|
- graphpoint.add(new Point(x, y));
|
|
|
- } else
|
|
|
- // else its an ID
|
|
|
- sav = object.get(k).getAsInt();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- switch (type) {
|
|
|
- case SWITCH:
|
|
|
- HolonSwitch sw = (HolonSwitch) objDispatch.get(sav);
|
|
|
- sw.setGraphPoints(graphpoint);
|
|
|
- break;
|
|
|
- case ELEMENT:
|
|
|
- HolonElement ele = eleDispatch.get(sav);
|
|
|
- ele.setGraphPoints(graphpoint);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void loadStatisticGraph(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- JsonObject object = jsonElement.getAsJsonObject();
|
|
|
- model.getGraphTable().clear();
|
|
|
- model.getStatisticData().add(object);
|
|
|
- }
|
|
|
-
|
|
|
- private void loadTracked(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- JsonObject object = jsonElement.getAsJsonObject();
|
|
|
- List<String> keys = getKeys(object);
|
|
|
-
|
|
|
- for (String k : keys) {
|
|
|
- int id = object.get(k).getAsInt();
|
|
|
- model.getTrackingObj().add(objDispatch.get(id));
|
|
|
- model.addObjectsToGraphListeners();
|
|
|
- if (objDispatch.get(id) instanceof HolonObject) {
|
|
|
- ((HolonObject) objDispatch.get(id)).updateTrackingInfo();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private File readArchive(String path, File src) throws IOException, ArchiveException {
|
|
|
- File tmp = Files.createTempDirectory("tmpHolon").toFile();
|
|
|
- tmp.deleteOnExit();
|
|
|
- InputStream input = new FileInputStream(src);
|
|
|
- ArchiveInputStream stream = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP,
|
|
|
- input);
|
|
|
-
|
|
|
- ArchiveEntry entry = stream.getNextEntry();
|
|
|
- while (entry != null) {
|
|
|
- // String entryName = checkOS(entry.getName());
|
|
|
- File file = new File(tmp, entry.getName());
|
|
|
- file.getParentFile().mkdirs();
|
|
|
- OutputStream output = new FileOutputStream(file);
|
|
|
- IOUtils.copy(stream, output);
|
|
|
- output.close();
|
|
|
- // file.createNewFile();
|
|
|
- entry = stream.getNextEntry();
|
|
|
- }
|
|
|
-
|
|
|
- stream.close();
|
|
|
- input.close();
|
|
|
-
|
|
|
- return tmp;
|
|
|
- }
|
|
|
-
|
|
|
- private String checkOS(String entryName) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- String os = System.getProperty("os.name").toLowerCase();
|
|
|
- String ret = entryName;
|
|
|
- String partition = System.getProperty("user.home");
|
|
|
-
|
|
|
- if (!ret.contains("HolonGUI"))
|
|
|
- return ret;
|
|
|
-
|
|
|
- if (os.contains("windows")) {
|
|
|
- ret = ret.replace("/", "\\");
|
|
|
- ret = System.getProperty("user.home") + "\\.config"
|
|
|
- + ret.substring(ret.indexOf("\\HolonGUI\\"), ret.length());
|
|
|
-
|
|
|
- }
|
|
|
- if (os.contains("mac")) {
|
|
|
- // dosmth
|
|
|
- ret = ret.replace("\\", "/");
|
|
|
- ret = System.getProperty("user.home") + "/.config" + ret.substring(ret.indexOf("/HolonGUI/"), ret.length());
|
|
|
- }
|
|
|
- if (os.contains("linux")) {
|
|
|
- // dosmth
|
|
|
- ret = ret.replace("\\", "/");
|
|
|
- ret = System.getProperty("user.home") + "/.config" + ret.substring(ret.indexOf("/HolonGUI/"), ret.length());
|
|
|
- }
|
|
|
- if (os.contains("solaris")) {
|
|
|
- // dosmth
|
|
|
- }
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Init new Arrays which havent been serialized along the object
|
|
|
- *
|
|
|
- * @param obj
|
|
|
- */
|
|
|
- public void initObjects(AbstractCpsObject obj) {
|
|
|
-
|
|
|
- obj.setConnections(new ArrayList<CpsEdge>());
|
|
|
- obj.setTags(new ArrayList<Integer>());
|
|
|
- obj.setPseudoTags(new ArrayList<Integer>());
|
|
|
-
|
|
|
- if (obj instanceof HolonObject) {
|
|
|
- ((HolonObject) obj).setElements(new ArrayList<HolonElement>());
|
|
|
-
|
|
|
- ((HolonObject) obj).setTrackingProd(new float[100]);
|
|
|
- ((HolonObject) obj).setTrackingCons(new float[100]);
|
|
|
- }
|
|
|
-
|
|
|
- if (obj instanceof HolonSwitch) {
|
|
|
- ((HolonSwitch) obj).setActiveAt(true);
|
|
|
- ((HolonSwitch) obj).setGraphPoints(new LinkedList<Point>());
|
|
|
- }
|
|
|
-
|
|
|
- if (obj instanceof CpsUpperNode) {
|
|
|
- ((CpsUpperNode) obj).setNodes(new ArrayList<AbstractCpsObject>());
|
|
|
- ((CpsUpperNode) obj).setNodeEdges(new ArrayList<CpsEdge>());
|
|
|
- ((CpsUpperNode) obj).setOldEdges(new ArrayList<CpsEdge>());
|
|
|
- ((CpsUpperNode) obj).setNodesIdx(new HashMap<Integer, Integer>());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Init Elements
|
|
|
- *
|
|
|
- * @param ele
|
|
|
- */
|
|
|
- public void initElements(HolonElement ele) {
|
|
|
-
|
|
|
- ele.setAvailableEnergyPerElementAt(ele.getEnergyPerElement());
|
|
|
- ele.setGraphPoints(new LinkedList<Point>());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Init Edges
|
|
|
- *
|
|
|
- * @param edge
|
|
|
- */
|
|
|
- public void initCpsEdge(CpsEdge edge) {
|
|
|
- edge.setTags(new ArrayList<Integer>());
|
|
|
- edge.setPseudoTag(new ArrayList<Integer>());
|
|
|
- edge.setA(null);
|
|
|
- edge.setB(null);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get Set of Keys
|
|
|
- *
|
|
|
- * @param json
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<String> getKeys(JsonObject json) {
|
|
|
- return json.entrySet().stream().map(i -> i.getKey()).collect(Collectors.toCollection(ArrayList::new));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * enum Mode.
|
|
|
- */
|
|
|
- public enum MODE {
|
|
|
- COMPLETE, PARTIAL, CATEGORY
|
|
|
- }
|
|
|
-
|
|
|
- public enum EDGETYPE {
|
|
|
- CANVAS, CONNECTION, NODE, OLD
|
|
|
- }
|
|
|
-
|
|
|
- public enum GRAPHTYPE {
|
|
|
- SWITCH, ELEMENT
|
|
|
- }
|
|
|
+ private Model model;
|
|
|
+ private CategoryController cgC;
|
|
|
+ private CanvasController cvsC;
|
|
|
+ private ObjectController objC;
|
|
|
+ private NodeController uppC;
|
|
|
+ private MultiPurposeController mpC;
|
|
|
+ private JsonParser parser;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Constructor.
|
|
|
+ *
|
|
|
+ * @param model Model
|
|
|
+ * @param cg CategoryController
|
|
|
+ * @param cvs CanvasController
|
|
|
+ * @param obj ObjectController
|
|
|
+ * @param mp MultiPurposeController
|
|
|
+ */
|
|
|
+ LoadController(Model model, CategoryController cg, CanvasController cvs, ObjectController obj,
|
|
|
+ NodeController uppC, MultiPurposeController mp) {
|
|
|
+ this.model = model;
|
|
|
+ this.cgC = cg;
|
|
|
+ this.cvsC = cvs;
|
|
|
+ this.objC = obj;
|
|
|
+ this.uppC = uppC;
|
|
|
+ this.mpC = mp;
|
|
|
+ this.parser = new JsonParser();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Reads the the JSON File and load the state into the Model.
|
|
|
+ *
|
|
|
+ * @param path the Path
|
|
|
+ * @throws IOException exception
|
|
|
+ */
|
|
|
+ void readSave(String path) throws IOException, ArchiveException {
|
|
|
+
|
|
|
+ File src = new File(path);
|
|
|
+ File folder = readArchive(src);
|
|
|
+ folder.deleteOnExit();
|
|
|
+ String trim = folder.getPath().substring(0,
|
|
|
+ folder.getPath().lastIndexOf(folder.getName()) + folder.getName().length());
|
|
|
+
|
|
|
+ forwardFiles(folder, trim);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ void readJson(String path) throws IOException {
|
|
|
+ JsonObject json = (JsonObject) parser.parse(new FileReader(path));
|
|
|
+ // get all keys via stream
|
|
|
+ List<String> keys = getKeys(json);
|
|
|
+ List<String> edges = keys.stream().filter(key -> key.contains("EDGE"))
|
|
|
+ .collect(Collectors.toCollection(ArrayList::new));
|
|
|
+
|
|
|
+ HashMap<Integer, AbstractCpsObject> objDispatch = new HashMap<>();
|
|
|
+ HashMap<Integer, HolonElement> eleDispatch = new HashMap<>();
|
|
|
+
|
|
|
+ initialize(json);
|
|
|
+ forwardObjects(keys, json, objDispatch, eleDispatch);
|
|
|
+ forwardEdges(edges, json, objDispatch);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Loads the Files from the Savefile
|
|
|
+ *
|
|
|
+ * @param trim the part of the file's path to be trimmed
|
|
|
+ * @throws IOException if anythings goes wrong reading the files
|
|
|
+ */
|
|
|
+ private void forwardFiles(File folder, String trim) throws IOException {
|
|
|
+ for (File file : folder.listFiles()) {
|
|
|
+ File dst = new File(
|
|
|
+ System.getProperty("user.home") + "/.config/HolonGUI/" + file.getPath().replace(trim, ""));
|
|
|
+
|
|
|
+ if (file.getName().contains(".json"))
|
|
|
+ readJson(file.getPath());
|
|
|
+ else if (file.isDirectory())
|
|
|
+ forwardFiles(file, trim);
|
|
|
+ else {
|
|
|
+ dst.getParentFile().mkdirs();
|
|
|
+ Files.copy(file.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * distribute the Edges
|
|
|
+ */
|
|
|
+ private void forwardEdges(List<String> edges, JsonObject json, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
+
|
|
|
+ List<String> conn = new ArrayList<>();
|
|
|
+
|
|
|
+ for (String edge : edges) {
|
|
|
+ if (edge.contains("CVSEDGE"))
|
|
|
+ loadEdge(EDGETYPE.CANVAS, json.get(edge), objDispatch);
|
|
|
+ if (edge.contains("CONNEDGE"))
|
|
|
+ conn.add(edge);
|
|
|
+ if (edge.contains("NODE"))
|
|
|
+ loadEdge(EDGETYPE.NODE, json.get(edge), objDispatch);
|
|
|
+ if (edge.contains("OLD"))
|
|
|
+ loadEdge(EDGETYPE.OLD, json.get(edge), objDispatch);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String edge : conn) {
|
|
|
+ loadEdge(EDGETYPE.CONNECTION, json.get(edge), objDispatch);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Distribute the given keys for right processing
|
|
|
+ */
|
|
|
+ private void forwardObjects(List<String> keys, JsonObject json, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
+ HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
+ for (String key : keys) {
|
|
|
+ if (key.contains("CATEGORY"))
|
|
|
+ loadCategory(json.get(key));
|
|
|
+ if (key.contains("CGOBJECT"))
|
|
|
+ loadCategoryObject(json.get(key));
|
|
|
+ if (key.contains("CGELEMENT"))
|
|
|
+ loadCategoryElements(json.get(key));
|
|
|
+ if (key.contains("CVSOBJECT"))
|
|
|
+ loadCanvasObject(json.get(key), objDispatch);
|
|
|
+ if (key.contains("CVSELEMENT"))
|
|
|
+ loadCanvasElements(json.get(key), objDispatch, eleDispatch);
|
|
|
+ if (key.contains("SWUNITGRAPH"))
|
|
|
+ loadUnitGraph(GRAPHTYPE.SWITCH, json.get(key), objDispatch, null);
|
|
|
+ if (key.contains("ELEUNITGRAPH"))
|
|
|
+ loadUnitGraph(GRAPHTYPE.ELEMENT, json.get(key), null, eleDispatch);
|
|
|
+ if (key.contains("TRACKED"))
|
|
|
+ loadTracked(json.get(key), objDispatch);
|
|
|
+ if (key.contains("STATSGRAPH"))
|
|
|
+ loadStatisticGraph(json.get(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Init the Global Parameters
|
|
|
+ */
|
|
|
+ private void initialize(JsonObject json) {
|
|
|
+
|
|
|
+ switch (MODE.valueOf(json.get("MODE").getAsString())) {
|
|
|
+ case COMPLETE:
|
|
|
+ model.setCvsObjIdx(new HashMap<>());
|
|
|
+ model.setObjectsOnCanvas(new ArrayList<>());
|
|
|
+ model.setEdgesOnCanvas(new ArrayList<>());
|
|
|
+ model.setTrackingObj(new ArrayList<>());
|
|
|
+ model.setStatisticData(new ArrayList<>());
|
|
|
+ model.setHashcodeMap(new HashMap<>());
|
|
|
+ model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
|
|
|
+ model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
|
|
|
+ IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
|
|
|
+ IdCounterElem.setCounter(json.get("IDCOUNTERELEMENT").getAsInt());
|
|
|
+ break;
|
|
|
+ case PARTIAL:
|
|
|
+ model.setCvsObjIdx(new HashMap<>());
|
|
|
+ model.setObjectsOnCanvas(new ArrayList<>());
|
|
|
+ model.setEdgesOnCanvas(new ArrayList<>());
|
|
|
+ model.setHashcodeMap(new HashMap<>());
|
|
|
+ model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
|
|
|
+ model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
|
|
|
+ IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
|
|
|
+ IdCounterElem.setCounter(json.get("IDCOUNTERELEMENT").getAsInt());
|
|
|
+ break;
|
|
|
+ case CATEGORY:
|
|
|
+ model.setCgIdx(new HashMap<>());
|
|
|
+ model.setCategories(new ArrayList<>());
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load a given Category
|
|
|
+ */
|
|
|
+ private void loadCategory(JsonElement jsonElement) {
|
|
|
+ if (mpC.searchCat(jsonElement.getAsString()) == null)
|
|
|
+ cgC.addCategory(new Category(jsonElement.getAsString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load a given Object in Category by Deserialization
|
|
|
+ */
|
|
|
+ private void loadCategoryObject(JsonElement jsonElement) {
|
|
|
+ AbstractCpsObject temp = model.getGson().fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
|
|
|
+ temp.setImage(checkOS(temp.getImage()));
|
|
|
+ initObjects(temp);
|
|
|
+ if (mpC.searchCatObj(mpC.searchCat(temp.getSav()), temp.getObjName()) != null)
|
|
|
+ cgC.deleteObject(temp.getSav(), temp.getObjName());
|
|
|
+ cgC.addObject(mpC.searchCat(temp.getSav()), temp);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load a given Element in Category by Deserialization
|
|
|
+ */
|
|
|
+ private void loadCategoryElements(JsonElement jsonElement) {
|
|
|
+ HolonElement temp = model.getGson().fromJson(jsonElement.getAsJsonObject().get("properties").getAsJsonObject(),
|
|
|
+ HolonElement.class);
|
|
|
+ initElements(temp);
|
|
|
+ objC.addElementIntoCategoryObject(temp.getSaving().getKey(), temp.getSaving().getValue(), temp);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load a given Object in Canvas by Deserialization
|
|
|
+ */
|
|
|
+ private void loadCanvasObject(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
+ AbstractCpsObject temp = model.getGson().fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
|
|
|
+ initObjects(temp);
|
|
|
+ temp.setImage(checkOS(temp.getImage()));
|
|
|
+ if (temp instanceof CpsUpperNode) {
|
|
|
+ model.getHashcodeMap().put(jsonElement.getAsJsonObject().get("hash").getAsInt(), (CpsUpperNode) temp);
|
|
|
+ ((CpsUpperNode) temp).setLeftBorder(jsonElement.getAsJsonObject().get("properties").getAsJsonObject().get("leftBorder").getAsInt());
|
|
|
+ }
|
|
|
+ // if its stored before on the canvas just put it there
|
|
|
+ if (temp.getSav().equals("CVS")) {
|
|
|
+ cvsC.addObject(temp);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // else look up the table and put it into the right Uppernode
|
|
|
+ CpsUpperNode temp2 = (CpsUpperNode) objDispatch.get(Integer.parseInt(temp.getSav()));
|
|
|
+ uppC.addObjectInUpperNode(temp, temp2);
|
|
|
+ }
|
|
|
+
|
|
|
+ objDispatch.put(temp.getId(), temp);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load a given Element in Canvas by Deserialization
|
|
|
+ */
|
|
|
+ private void loadCanvasElements(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
+ HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
+
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+
|
|
|
+ HolonElement temp = model.getGson().fromJson(object.get("properties"), HolonElement.class);
|
|
|
+ initElements(temp);
|
|
|
+ // id which Object it was stored before
|
|
|
+ int stored = object.get("ID").getAsInt();
|
|
|
+ // lookup that object
|
|
|
+ HolonObject temp2 = (HolonObject) objDispatch.get(stored);
|
|
|
+ // add it
|
|
|
+ objC.addElement(temp2, temp);
|
|
|
+ // store element also inside a table
|
|
|
+ eleDispatch.put(temp.getId(), temp);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load a given Edge by Deserialization
|
|
|
+ */
|
|
|
+ private void loadEdge(EDGETYPE type, JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ CpsEdge temp = model.getGson().fromJson(object.get("properties"), CpsEdge.class);
|
|
|
+ initCpsEdge(temp);
|
|
|
+ // look for A and B inside the Table
|
|
|
+ temp.setA(objDispatch.get(object.get("A").getAsInt()));
|
|
|
+ temp.setB(objDispatch.get(object.get("B").getAsInt()));
|
|
|
+
|
|
|
+ int sav;
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case CANVAS:
|
|
|
+ // if in canvas add it into the canvas but delete connection before
|
|
|
+ model.getEdgesOnCanvas().add(temp);
|
|
|
+ break;
|
|
|
+ case CONNECTION:
|
|
|
+ // if no duplicates in connection store them into the given A and B
|
|
|
+ if (!uppC.lookforDuplicates(temp.getA(), temp.getB(), temp.getA().getConnections()))
|
|
|
+ temp.getA().getConnections().add(temp);
|
|
|
+ if (!uppC.lookforDuplicates(temp.getA(), temp.getB(), temp.getB().getConnections()))
|
|
|
+ temp.getB().getConnections().add(temp);
|
|
|
+ break;
|
|
|
+ case NODE:
|
|
|
+ // put it into given nodeofnode
|
|
|
+ sav = object.get("ID").getAsInt();
|
|
|
+ ((CpsUpperNode) objDispatch.get(sav)).getNodeEdges().add(temp);
|
|
|
+ break;
|
|
|
+ case OLD:
|
|
|
+ // same as above
|
|
|
+ sav = object.get("ID").getAsInt();
|
|
|
+ ((CpsUpperNode) objDispatch.get(sav)).getOldEdges().add(temp);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (object.get("connection").getAsBoolean() && !type.equals(EDGETYPE.CONNECTION)) {
|
|
|
+ temp.getA().getConnections().add(temp);
|
|
|
+ temp.getB().getConnections().add(temp);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load a Unitgraph by Deserialization
|
|
|
+ */
|
|
|
+ private void loadUnitGraph(GRAPHTYPE type, JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
+ HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
+
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ List<String> keys = getKeys(object);
|
|
|
+ String p;
|
|
|
+ int mid, x, y;
|
|
|
+
|
|
|
+ LinkedList<Point> graphpoint = new LinkedList<>();
|
|
|
+ int sav = 0;
|
|
|
+ // foreach Point in the graph restore it
|
|
|
+ for (String k : keys) {
|
|
|
+ if (!k.equals("ID")) {
|
|
|
+ p = object.get(k).getAsString();
|
|
|
+ mid = p.indexOf(':');
|
|
|
+ x = Integer.parseInt(p.substring(0, mid));
|
|
|
+ y = Integer.parseInt(p.substring(mid + 1, p.length()));
|
|
|
+ graphpoint.add(new Point(x, y));
|
|
|
+ } else
|
|
|
+ // else its an ID
|
|
|
+ sav = object.get(k).getAsInt();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case SWITCH:
|
|
|
+ HolonSwitch sw = (HolonSwitch) objDispatch.get(sav);
|
|
|
+ sw.setGraphPoints(graphpoint);
|
|
|
+ break;
|
|
|
+ case ELEMENT:
|
|
|
+ HolonElement ele = eleDispatch.get(sav);
|
|
|
+ ele.setGraphPoints(graphpoint);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadStatisticGraph(JsonElement jsonElement) {
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ model.getGraphTable().clear();
|
|
|
+ model.getStatisticData().add(object);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadTracked(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ List<String> keys = getKeys(object);
|
|
|
+
|
|
|
+ for (String k : keys) {
|
|
|
+ int id = object.get(k).getAsInt();
|
|
|
+ model.getTrackingObj().add(objDispatch.get(id));
|
|
|
+ model.addObjectsToGraphListeners();
|
|
|
+ if (objDispatch.get(id) instanceof HolonObject) {
|
|
|
+ ((HolonObject) objDispatch.get(id)).updateTrackingInfo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private File readArchive(File src) throws IOException, ArchiveException {
|
|
|
+ File tmp = Files.createTempDirectory("tmpHolon").toFile();
|
|
|
+ tmp.deleteOnExit();
|
|
|
+ InputStream input = new FileInputStream(src);
|
|
|
+ ArchiveInputStream stream = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP,
|
|
|
+ input);
|
|
|
+
|
|
|
+ ArchiveEntry entry = stream.getNextEntry();
|
|
|
+ while (entry != null) {
|
|
|
+ // String entryName = checkOS(entry.getName());
|
|
|
+ File file = new File(tmp, entry.getName());
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
+ OutputStream output = new FileOutputStream(file);
|
|
|
+ IOUtils.copy(stream, output);
|
|
|
+ output.close();
|
|
|
+ // file.createNewFile();
|
|
|
+ entry = stream.getNextEntry();
|
|
|
+ }
|
|
|
+
|
|
|
+ stream.close();
|
|
|
+ input.close();
|
|
|
+
|
|
|
+ return tmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String checkOS(String entryName) {
|
|
|
+ String os = System.getProperty("os.name").toLowerCase();
|
|
|
+ String ret = entryName;
|
|
|
+// String partition = System.getProperty("user.home");
|
|
|
+
|
|
|
+ if (!ret.contains("HolonGUI"))
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ if (os.contains("windows")) {
|
|
|
+ ret = ret.replace("/", "\\");
|
|
|
+ ret = System.getProperty("user.home") + "\\.config"
|
|
|
+ + ret.substring(ret.indexOf("\\HolonGUI\\"), ret.length());
|
|
|
+
|
|
|
+ }
|
|
|
+ if (os.contains("mac")) {
|
|
|
+ // dosmth
|
|
|
+ ret = ret.replace("\\", "/");
|
|
|
+ ret = System.getProperty("user.home") + "/.config" + ret.substring(ret.indexOf("/HolonGUI/"), ret.length());
|
|
|
+ }
|
|
|
+ if (os.contains("linux")) {
|
|
|
+ // dosmth
|
|
|
+ ret = ret.replace("\\", "/");
|
|
|
+ ret = System.getProperty("user.home") + "/.config" + ret.substring(ret.indexOf("/HolonGUI/"), ret.length());
|
|
|
+ }
|
|
|
+// if (os.contains("solaris")) {
|
|
|
+// // dosmth
|
|
|
+// }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Init new Arrays which haven't been serialized along the object
|
|
|
+ */
|
|
|
+ void initObjects(AbstractCpsObject obj) {
|
|
|
+
|
|
|
+ obj.setConnections(new ArrayList<>());
|
|
|
+ obj.setTags(new ArrayList<>());
|
|
|
+ obj.setPseudoTags(new ArrayList<>());
|
|
|
+
|
|
|
+ if (obj instanceof HolonObject) {
|
|
|
+ ((HolonObject) obj).setElements(new ArrayList<>());
|
|
|
+
|
|
|
+ ((HolonObject) obj).setTrackingProd(new float[100]);
|
|
|
+ ((HolonObject) obj).setTrackingCons(new float[100]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (obj instanceof HolonSwitch) {
|
|
|
+ ((HolonSwitch) obj).setActiveAt(true);
|
|
|
+ ((HolonSwitch) obj).setGraphPoints(new LinkedList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (obj instanceof CpsUpperNode) {
|
|
|
+ ((CpsUpperNode) obj).setNodes(new ArrayList<>());
|
|
|
+ ((CpsUpperNode) obj).setNodeEdges(new ArrayList<>());
|
|
|
+ ((CpsUpperNode) obj).setOldEdges(new ArrayList<>());
|
|
|
+ ((CpsUpperNode) obj).setNodesIdx(new HashMap<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Init Elements (set available energy, set new graph points)
|
|
|
+ *
|
|
|
+ * @param ele the element to be initialized
|
|
|
+ */
|
|
|
+ void initElements(HolonElement ele) {
|
|
|
+ ele.setAvailableEnergyPerElementAt(ele.getEnergyPerElement());
|
|
|
+ ele.setGraphPoints(new LinkedList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Init Edges (set tags and reset source and target)
|
|
|
+ *
|
|
|
+ * @param edge the edge to be initialized
|
|
|
+ */
|
|
|
+ void initCpsEdge(CpsEdge edge) {
|
|
|
+ edge.setTags(new ArrayList<>());
|
|
|
+ edge.setPseudoTag(new ArrayList<>());
|
|
|
+ edge.setA(null);
|
|
|
+ edge.setB(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get Set of Keys
|
|
|
+ *
|
|
|
+ * @return the keys from the json object
|
|
|
+ */
|
|
|
+ List<String> getKeys(JsonObject json) {
|
|
|
+ return json.entrySet().stream().map(i -> i.getKey()).collect(Collectors.toCollection(ArrayList::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * enum Mode.
|
|
|
+ */
|
|
|
+ public enum MODE {
|
|
|
+ COMPLETE, PARTIAL, CATEGORY
|
|
|
+ }
|
|
|
+
|
|
|
+ public enum EDGETYPE {
|
|
|
+ CANVAS, CONNECTION, NODE, OLD
|
|
|
+ }
|
|
|
+
|
|
|
+ public enum GRAPHTYPE {
|
|
|
+ SWITCH, ELEMENT
|
|
|
+ }
|
|
|
|
|
|
}
|