|
@@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collector;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -28,6 +29,7 @@ import TypeAdapter.PositionAdapter;
|
|
|
import classes.Category;
|
|
|
import classes.CpsEdge;
|
|
|
import classes.CpsNode;
|
|
|
+import classes.CpsUpperNode;
|
|
|
import classes.AbstractCpsObject;
|
|
|
import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
@@ -50,18 +52,10 @@ public class LoadController {
|
|
|
COMPLETE, PARTIAL
|
|
|
}
|
|
|
|
|
|
- public enum TYPE {
|
|
|
- CATEGORY, CANVAS
|
|
|
- }
|
|
|
-
|
|
|
public enum EDGETYPE {
|
|
|
CANVAS, CONNECTION, NODE, OLD
|
|
|
}
|
|
|
|
|
|
- public enum NUMTYPE {
|
|
|
- CATEGORY, OBJECT, ELEMENT, EDGE, CONNECTION, NODEEDGE, OLDEDGE, UNITGRAPH
|
|
|
- }
|
|
|
-
|
|
|
public enum GRAPHTYPE {
|
|
|
SWITCH, ELEMENT
|
|
|
}
|
|
@@ -70,10 +64,10 @@ public class LoadController {
|
|
|
private CategoryController cgC;
|
|
|
private CanvasController cvsC;
|
|
|
private ObjectController objC;
|
|
|
+ private NodeController uppC;
|
|
|
private MultiPurposeController mpC;
|
|
|
private Gson gson;
|
|
|
- // uninitialized arrays only init when needed
|
|
|
- ArrayList<String> jCat, jObj, jEle, jEdge, jConn, jNodeEdge, jOldEdge, jUnitGraph;
|
|
|
+ private JsonParser parser;
|
|
|
|
|
|
/**
|
|
|
* Constructor.
|
|
@@ -89,11 +83,13 @@ public class LoadController {
|
|
|
* @param mp
|
|
|
* MultiPurposeController
|
|
|
*/
|
|
|
- public LoadController(Model model, CategoryController cg, CanvasController cvs, ObjectController obj, MultiPurposeController mp) {
|
|
|
+ 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;
|
|
|
initGson();
|
|
|
}
|
|
@@ -108,281 +104,300 @@ public class LoadController {
|
|
|
*/
|
|
|
public void readJson(String path) throws IOException {
|
|
|
|
|
|
- JsonParser parser = new JsonParser();
|
|
|
JsonObject json = (JsonObject) parser.parse(new FileReader(path));
|
|
|
-
|
|
|
// get all keys via stream
|
|
|
- List<String> keys = json.entrySet().stream().map(i -> i.getKey())
|
|
|
+ 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);
|
|
|
- distribute(keys, json, parser);
|
|
|
-
|
|
|
-// for (Object key : keys) {
|
|
|
-// if (key.equals("CG"))
|
|
|
-// readCategory((JSONArray) json.get((String) key));
|
|
|
-// else if (key.equals("ID"))
|
|
|
-// IdCounter.setCounter(Integer.parseInt(json.get(key.toString()).toString()));
|
|
|
-// // else if (key.equals("SIZEX"))
|
|
|
-// // global.setCanvasX(Integer.parseInt(json.get(key.toString()).toString()));
|
|
|
-// // else if (key.equals("SIZEY"))
|
|
|
-// // global.setCanvasY(Integer.parseInt(json.get(key.toString()).toString()));
|
|
|
-// else if (key.toString().contains("CGO") || key.toString().contains("CVSO"))
|
|
|
-// obj.add(key.toString());
|
|
|
-// else if (key.toString().contains("CGE") || key.toString().contains("CVSE"))
|
|
|
-// ele.add(key.toString());
|
|
|
-// else if (key.toString().contains("EDGE"))
|
|
|
-// edge.add(key.toString());
|
|
|
-// else if (key.toString().contains("CGGP") || key.toString().contains("CVSGP"))
|
|
|
-// gp.add(key.toString());
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// dispatch(obj, json);
|
|
|
-// dispatch(ele, json);
|
|
|
-// dispatch(edge, json);
|
|
|
-// dispatch(gp, json);
|
|
|
+ distribute(keys, json, objDispatch, eleDispatch);
|
|
|
+ distEdges(edges, json, objDispatch);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void distEdges(List<String> edges, JsonObject json, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
|
|
|
+ for (String edge : edges) {
|
|
|
+ if (edge.contains("CVSEDGE"))
|
|
|
+ loadEdge(EDGETYPE.CANVAS, json.get(edge), objDispatch);
|
|
|
+ if (edge.contains("CONNEDGE"))
|
|
|
+ loadEdge(EDGETYPE.CONNECTION, json.get(edge), objDispatch);
|
|
|
+ if (edge.contains("NODE"))
|
|
|
+ loadEdge(EDGETYPE.NODE, json.get(edge), objDispatch);
|
|
|
+ if (edge.contains("OLD"))
|
|
|
+ loadEdge(EDGETYPE.OLD, json.get(edge), objDispatch);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void distribute(List<String> keys, JsonObject json, JsonParser parser) {
|
|
|
+ private void distribute(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"))
|
|
|
+ if (key.contains("CATEGORY"))
|
|
|
loadCategory(json.get(key));
|
|
|
- if(key.contains("CGOBJECT"))
|
|
|
- loadCategoryObject(TYPE.CATEGORY, json.get(key).getAsJsonObject());
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- private void loadCategoryObject(TYPE type, JsonObject jsonElement) {
|
|
|
+ private void loadUnitGraph(GRAPHTYPE type, JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
+ HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
// TODO Auto-generated method stub
|
|
|
- AbstractCpsObject temp = gson.fromJson(jsonElement., AbstractCpsObject.class);
|
|
|
- cgC.addObject(mpC.searchCat(temp.getSav()), temp);
|
|
|
- }
|
|
|
|
|
|
- private void loadCategory(JsonElement jsonElement) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- cgC.addCategory(new Category(jsonElement.getAsString()));
|
|
|
- }
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ List<String> keys = getKeys(object);
|
|
|
+ String p = null;
|
|
|
+ int mid, x, y = 0;
|
|
|
|
|
|
- private void initialize(List<String> keys, JsonObject json) {
|
|
|
+ LinkedList<Point> graphpoint = new LinkedList<>();
|
|
|
+ int sav = 0;
|
|
|
|
|
|
- switch (MODE.valueOf(json.get("MODE").getAsString())) {
|
|
|
- case COMPLETE:
|
|
|
- model.setCgIdx(new HashMap<String, Integer>());
|
|
|
- model.setCategories(new ArrayList<Category>());
|
|
|
- model.setCvsObjIdx(new HashMap<Integer, Integer>());
|
|
|
- model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
|
|
|
- model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
|
|
|
- model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
|
|
|
- model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
|
|
|
+ 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
|
|
|
+ sav = object.get(k).getAsInt();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case SWITCH:
|
|
|
+ HolonSwitch sw = (HolonSwitch) objDispatch.get(sav);
|
|
|
+ sw.setGraphPoints(graphpoint);
|
|
|
break;
|
|
|
- case PARTIAL:
|
|
|
- model.setCvsObjIdx(new HashMap<Integer, Integer>());
|
|
|
- model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
|
|
|
- model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
|
|
|
+ case ELEMENT:
|
|
|
+ HolonElement ele = eleDispatch.get(sav);
|
|
|
+ ele.setGraphPoints(graphpoint);
|
|
|
break;
|
|
|
-
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * dispatch the Keys into the right processing.
|
|
|
- *
|
|
|
- * @param input
|
|
|
- * input
|
|
|
- * @param json
|
|
|
- * Json
|
|
|
- */
|
|
|
- public void dispatch(ArrayList<String> input, JSONObject json) {
|
|
|
-
|
|
|
- for (String str : input) {
|
|
|
- if (str.contains("CGO")) {
|
|
|
- readCategoryObject((JSONArray) json.get(str));
|
|
|
- } else if (str.contains("CVSO")) {
|
|
|
- readCanvasObject((JSONArray) json.get(str));
|
|
|
- } else if (str.contains("CGE") || str.contains("CVSE")) {
|
|
|
- readElement((JSONArray) json.get(str));
|
|
|
- } else if (str.contains("EDGE")) {
|
|
|
- readEdge((JSONArray) json.get(str));
|
|
|
- } else if (str.contains("CGGP") || str.contains("CVSGP")) {
|
|
|
- readElementGraph((JSONArray) json.get(str));
|
|
|
- }
|
|
|
+ private void loadEdge(EDGETYPE type, JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ CpsEdge temp = gson.fromJson(object.get("properties"), CpsEdge.class);
|
|
|
+ initCpsEdge(temp);
|
|
|
+ temp.setA(objDispatch.get(object.get("A").getAsInt()));
|
|
|
+ System.out.println(temp.getA());
|
|
|
+ temp.setB(objDispatch.get(object.get("B").getAsInt()));
|
|
|
+
|
|
|
+ int sav = 0;
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case CANVAS:
|
|
|
+ model.getEdgesOnCanvas().add(temp);
|
|
|
+ temp.getA().getConnections().remove(temp);
|
|
|
+ temp.getB().getConnections().remove(temp);
|
|
|
+ break;
|
|
|
+ case CONNECTION:
|
|
|
+ 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:
|
|
|
+ sav = object.get("ID").getAsInt();
|
|
|
+ ((CpsUpperNode) objDispatch.get(sav)).getNodeEdges().add(temp);
|
|
|
+ break;
|
|
|
+ case OLD:
|
|
|
+ sav = object.get("ID").getAsInt();
|
|
|
+ ((CpsUpperNode) objDispatch.get(sav)).getOldEdges().add(temp);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Read all Categories from the JSON file.
|
|
|
*
|
|
|
- * @param arr
|
|
|
- * JSONArray
|
|
|
+ * @param jsonElement
|
|
|
+ * @param objDispatch
|
|
|
+ * @param eleDispatch
|
|
|
*/
|
|
|
- public void readCategory(JSONArray arr) {
|
|
|
-
|
|
|
- Iterator<Object> i = arr.iterator();
|
|
|
+ private void loadCanvasElements(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch,
|
|
|
+ HashMap<Integer, HolonElement> eleDispatch) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
|
|
|
- while (i.hasNext()) {
|
|
|
- cgC.addNewCategory(next(i));
|
|
|
- }
|
|
|
- }
|
|
|
+ JsonObject object = jsonElement.getAsJsonObject();
|
|
|
+ HolonElement temp = gson.fromJson(object.get("properties"), HolonElement.class);
|
|
|
+ initElements(temp);
|
|
|
|
|
|
- /**
|
|
|
- * Read all Objects in Category from the JSON File.
|
|
|
- *
|
|
|
- * @param arr
|
|
|
- * JSON Array
|
|
|
- */
|
|
|
- public void readCategoryObject(JSONArray arr) {
|
|
|
- Iterator<Object> i = arr.iterator();
|
|
|
+ int stored = object.get("ID").getAsInt();
|
|
|
|
|
|
- String type = next(i);
|
|
|
-
|
|
|
- if (type.equals("HolonObject")) {
|
|
|
- cgC.addNewHolonObject(mpC.searchCat(next(i)), next(i), new ArrayList<HolonElement>(), next(i));
|
|
|
- } else if (type.equals("HolonTransformer")) {
|
|
|
- cgC.addNewHolonTransformer(mpC.searchCat(next(i)), next(i), next(i));
|
|
|
- } else if (type.equals("HolonSwitch")) {
|
|
|
- cgC.addNewHolonSwitch(mpC.searchCat(next(i)), next(i), next(i));
|
|
|
- }
|
|
|
+ HolonObject temp2 = (HolonObject) objDispatch.get(stored);
|
|
|
|
|
|
+ objC.addElement(temp2, temp);
|
|
|
+ eleDispatch.put(temp.getId(), temp);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Read all Objects in Canvas from JSON File.
|
|
|
*
|
|
|
- * @param arr
|
|
|
- * JSON Array
|
|
|
+ * @param jsonElement
|
|
|
+ * @param objDispatch
|
|
|
*/
|
|
|
- public void readCanvasObject(JSONArray arr) {
|
|
|
- Iterator<Object> i = arr.iterator();
|
|
|
- AbstractCpsObject cps = null;
|
|
|
-
|
|
|
- String type = next(i);
|
|
|
-
|
|
|
- if (type.equals("HolonObject")) {
|
|
|
- cps = new HolonObject(next(i));
|
|
|
- } else if (type.equals("HolonTransformer")) {
|
|
|
- cps = new HolonTransformer(next(i));
|
|
|
- } else if (type.equals("HolonSwitch")) {
|
|
|
- cps = new HolonSwitch(next(i));
|
|
|
- } else if (type.equals("CpsNode")) {
|
|
|
- cps = new CpsNode(next(i));
|
|
|
+ private void loadCanvasObject(JsonElement jsonElement, HashMap<Integer, AbstractCpsObject> objDispatch) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ AbstractCpsObject temp = gson.fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
|
|
|
+ initObjects(temp);
|
|
|
+
|
|
|
+ if (temp.getSav().equals("CVS")) {
|
|
|
+ cvsC.addObject(temp);
|
|
|
+ } else {
|
|
|
+ CpsUpperNode temp2 = (CpsUpperNode) objDispatch.get(Integer.parseInt(temp.getSav()));
|
|
|
+ uppC.addObjectInUpperNode(temp, temp2);
|
|
|
}
|
|
|
|
|
|
- cps.setName(next(i));
|
|
|
- cps.setID(Integer.parseInt(next(i)));
|
|
|
- cps.setImage(next(i));
|
|
|
- cps.setPosition(Integer.parseInt(next(i)), Integer.parseInt(next(i)));
|
|
|
+ objDispatch.put(temp.getID(), temp);
|
|
|
|
|
|
- cvsC.addNewObject(cps);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Read all Elements in Category and Canvas from JSON File.
|
|
|
*
|
|
|
- * @param arr
|
|
|
- * JSON Array
|
|
|
+ * @param jsonElement
|
|
|
*/
|
|
|
- public void readElement(JSONArray arr) {
|
|
|
- Iterator<Object> i = arr.iterator();
|
|
|
-
|
|
|
- String sav = next(i);
|
|
|
- String obj = next(i);
|
|
|
-
|
|
|
- HolonElement ele = new HolonElement(next(i), Integer.parseInt(next(i)), Float.parseFloat(next(i)));
|
|
|
-
|
|
|
- if (sav.equals("CVS")) {
|
|
|
- ele.setActive(convert(Integer.parseInt(next(i))));
|
|
|
- objC.addElementIntoCanvasObject((HolonObject) mpC.searchByID(Integer.parseInt(obj)), ele);
|
|
|
- } else
|
|
|
- objC.addElementIntoCategoryObject(sav, obj, ele);
|
|
|
+ private void loadCategoryElements(JsonElement jsonElement) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ HolonElement temp = gson.fromJson(jsonElement.getAsJsonObject().get("properties").getAsJsonObject(),
|
|
|
+ HolonElement.class);
|
|
|
+ initElements(temp);
|
|
|
+ objC.addElementIntoCategoryObject(temp.getSav(), temp.getObj(), temp);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Read.
|
|
|
*
|
|
|
- * @param arr
|
|
|
- * JSON Array
|
|
|
+ * @param jsonElement
|
|
|
*/
|
|
|
- public void readEdge(JSONArray arr) {
|
|
|
- Iterator<Object> i = arr.iterator();
|
|
|
+ private void loadCategoryObject(JsonElement jsonElement) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ AbstractCpsObject temp = gson.fromJson(jsonElement.getAsJsonObject(), AbstractCpsObject.class);
|
|
|
+ initObjects(temp);
|
|
|
|
|
|
- CpsEdge edge = new CpsEdge(mpC.searchByID(Integer.parseInt(next(i))),
|
|
|
- mpC.searchByID(Integer.parseInt(next(i))));
|
|
|
- edge.setCapacity(Float.parseFloat(next(i)));
|
|
|
- edge.setFlow(Float.parseFloat(next(i)));
|
|
|
+ cgC.addObject(mpC.searchCat(temp.getSav()), temp);
|
|
|
+ }
|
|
|
|
|
|
- cvsC.addEdgeOnCanvas(edge);
|
|
|
+ private void loadCategory(JsonElement jsonElement) {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ cgC.addCategory(new Category(jsonElement.getAsString()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Read the Element Graph.
|
|
|
*
|
|
|
- * @param arr
|
|
|
- * JSON Array
|
|
|
+ * @param keys
|
|
|
+ * @param json
|
|
|
*/
|
|
|
- public void readElementGraph(JSONArray arr) {
|
|
|
- Iterator<Object> i = arr.iterator();
|
|
|
+ private void initialize(List<String> keys, JsonObject json) {
|
|
|
|
|
|
- String sav = next(i);
|
|
|
- HolonElement ele;
|
|
|
+ switch (MODE.valueOf(json.get("MODE").getAsString())) {
|
|
|
+ case COMPLETE:
|
|
|
+ model.setCgIdx(new HashMap<String, Integer>());
|
|
|
+ model.setCategories(new ArrayList<Category>());
|
|
|
+ model.setCvsObjIdx(new HashMap<Integer, Integer>());
|
|
|
+ model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
|
|
|
+ model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
|
|
|
+ model.setCanvasX(json.get("CANVAS_SIZE_X").getAsInt());
|
|
|
+ model.setCanvasX(json.get("CANVAS_SIZE_Y").getAsInt());
|
|
|
+ break;
|
|
|
+ case PARTIAL:
|
|
|
+ model.setCvsObjIdx(new HashMap<Integer, Integer>());
|
|
|
+ model.setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
|
|
|
+ model.setEdgesOnCanvas(new ArrayList<CpsEdge>());
|
|
|
+ break;
|
|
|
|
|
|
- if (sav.equals("CVS")) {
|
|
|
- ele = mpC.searchEle((HolonObject) mpC.searchByID(Integer.parseInt(next(i))), next(i));
|
|
|
- while (i.hasNext())
|
|
|
- ele.getGraphPoints().add(new Point(Integer.parseInt(next(i)), Integer.parseInt(next(i))));
|
|
|
- } else {
|
|
|
- ele = mpC.searchEle((HolonObject) mpC.searchCatObj(mpC.searchCat(sav), next(i)), next(i));
|
|
|
- while (i.hasNext())
|
|
|
- ele.getGraphPoints().add(new Point(Integer.parseInt(next(i)), Integer.parseInt(next(i))));
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get the Next Element from an Iterator.
|
|
|
- *
|
|
|
- * @param i
|
|
|
- * Iterator
|
|
|
- * @return next Element from the Iterator
|
|
|
- */
|
|
|
- public String next(Iterator<Object> i) {
|
|
|
- return i.next().toString();
|
|
|
+ IdCounter.setCounter(json.get("IDCOUNTER").getAsInt());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * converting saved Integers into Booleans.
|
|
|
- *
|
|
|
- * @param x
|
|
|
- * integer
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- public boolean convert(int x) {
|
|
|
- return x == 1 ? true : false;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Initialize the Gson with wanted parameters
|
|
|
*/
|
|
|
private void initGson() {
|
|
|
// TODO Auto-generated method stub
|
|
|
GsonBuilder builder = new GsonBuilder();
|
|
|
- builder.excludeFieldsWithoutExposeAnnotation().serializeNulls().setPrettyPrinting();
|
|
|
+ builder.serializeNulls();
|
|
|
builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter());
|
|
|
builder.registerTypeAdapter(Position.class, new PositionAdapter());
|
|
|
builder.registerTypeAdapter(Color.class, new ColorAdapter());
|
|
|
// use the builder and make a instance of the Gson
|
|
|
this.gson = builder.create();
|
|
|
+ this.parser = new JsonParser();
|
|
|
}
|
|
|
-
|
|
|
- private void initArrays() {
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Init new Arrays which havent been serialized along the object
|
|
|
+ *
|
|
|
+ * @param obj
|
|
|
+ */
|
|
|
+ private 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<HolonElement>());
|
|
|
+ ((HolonObject) obj).setEleIdx(new HashMap<String, Integer>());
|
|
|
+
|
|
|
+ ((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<AbstractCpsObject>());
|
|
|
+ ((CpsUpperNode) obj).setNodeEdges(new ArrayList<CpsEdge>());
|
|
|
+ ((CpsUpperNode) obj).setOldEdges(new ArrayList<CpsEdge>());
|
|
|
+ ((CpsUpperNode) obj).setNodesIdx(new HashMap<Integer, Integer>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param ele
|
|
|
+ */
|
|
|
+ private void initElements(HolonElement ele) {
|
|
|
+
|
|
|
+ ele.setEnergyAt(ele.getEnergy());
|
|
|
+ ele.setGraphPoints(new LinkedList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initCpsEdge(CpsEdge edge) {
|
|
|
+ edge.setTags(new ArrayList<>());
|
|
|
+ edge.setPseudoTag(new ArrayList<>());
|
|
|
+ edge.setA(null);
|
|
|
+ edge.setB(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getKeys(JsonObject json) {
|
|
|
+ return json.entrySet().stream().map(i -> i.getKey()).collect(Collectors.toCollection(ArrayList::new));
|
|
|
}
|
|
|
|
|
|
}
|