MinimumModel.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package model;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import classes.AbstractCanvasObject;
  5. import classes.Edge;
  6. import classes.Node;
  7. import model.DecoratedCable.CableState;
  8. import classes.GroupNode;
  9. import classes.HolonObject;
  10. import classes.HolonSwitch;
  11. /**
  12. * For DecoratedState And VisualRepresentationalState
  13. * @author Tom
  14. *
  15. */
  16. public class MinimumModel {
  17. private ArrayList<HolonObject> holonObjectList = new ArrayList<HolonObject>();
  18. private ArrayList<IntermediateCableWithState> cableList = new ArrayList<IntermediateCableWithState>();
  19. private ArrayList<Node> nodeList = new ArrayList<Node>();
  20. private ArrayList<HolonSwitch> switchList = new ArrayList<HolonSwitch>();
  21. //-->Only for Visual:
  22. private ArrayList<GroupNode> uppderNodeList = new ArrayList<GroupNode>();
  23. private HashMap<AbstractCanvasObject, GroupNode> inGroupObjects = new HashMap<>();
  24. HashMap<Edge, ArrayList<GroupNode>> inGroupEdges = new HashMap<Edge, ArrayList<GroupNode>>();
  25. //<--
  26. public HashMap<Edge, ArrayList<GroupNode>> getInGroupEdges() {
  27. return inGroupEdges;
  28. }
  29. public MinimumModel(ArrayList<AbstractCanvasObject> abstractObjectList, ArrayList<Edge> edgeList) {// Constructor because of old Model
  30. for (AbstractCanvasObject aCps : abstractObjectList) {
  31. if (aCps instanceof HolonObject) {
  32. holonObjectList.add((HolonObject) aCps);
  33. }
  34. else if (aCps instanceof Node) nodeList.add((Node) aCps);
  35. else if (aCps instanceof HolonSwitch) switchList.add((HolonSwitch) aCps);
  36. else if(aCps instanceof GroupNode) {
  37. addUpperObjects((GroupNode)aCps);
  38. uppderNodeList.add((GroupNode)aCps);
  39. }
  40. }
  41. for (Edge edge : edgeList) {
  42. this.cableList.add(new IntermediateCableWithState(edge, CableState.Working));
  43. AbstractCanvasObject objectA = edge.getA();
  44. AbstractCanvasObject objectB = edge.getB();
  45. if(inGroupObjects.containsKey(objectA) || inGroupObjects.containsKey(objectB)){
  46. ArrayList<GroupNode> list = new ArrayList<GroupNode>();
  47. if(inGroupObjects.containsKey(objectA)) {
  48. list.add(inGroupObjects.get(objectA));
  49. }
  50. if(inGroupObjects.containsKey(objectB)) {
  51. list.add(inGroupObjects.get(objectB));
  52. }
  53. inGroupEdges.put(edge, list);
  54. }
  55. }
  56. }
  57. private void addUpperObjects(GroupNode aUpperNode) {
  58. for(AbstractCanvasObject aCps : aUpperNode.getNodes()) {
  59. if (aCps instanceof HolonObject) holonObjectList.add((HolonObject) aCps);
  60. else if (aCps instanceof Node) nodeList.add((Node) aCps);
  61. else if (aCps instanceof HolonSwitch) switchList.add((HolonSwitch) aCps);
  62. else if(aCps instanceof GroupNode) {
  63. addUpperObjects((GroupNode)aCps);
  64. uppderNodeList.add((GroupNode)aCps);
  65. }
  66. inGroupObjects.put(aCps, aUpperNode);
  67. }
  68. }
  69. public ArrayList<HolonObject> getHolonObjectList() {
  70. return holonObjectList;
  71. }
  72. public void setHolonObjectList(ArrayList<HolonObject> holonObjectList) {
  73. this.holonObjectList = holonObjectList;
  74. }
  75. public ArrayList<IntermediateCableWithState> getEdgeList() {
  76. return cableList;
  77. }
  78. public void setEdgeList(ArrayList<IntermediateCableWithState> cableList) {
  79. this.cableList = cableList;
  80. }
  81. public ArrayList<Node> getNodeList() {
  82. return nodeList;
  83. }
  84. public void setNodeList(ArrayList<Node> nodeList) {
  85. this.nodeList = nodeList;
  86. }
  87. public ArrayList<HolonSwitch> getSwitchList() {
  88. return switchList;
  89. }
  90. public void setSwitchList(ArrayList<HolonSwitch> switchList) {
  91. this.switchList = switchList;
  92. }
  93. public ArrayList<GroupNode> getUppderNodeList() {
  94. return uppderNodeList;
  95. }
  96. public HashMap<AbstractCanvasObject, GroupNode> getInGroupObjects() {
  97. return inGroupObjects;
  98. }
  99. }