CpsUpperNode.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package classes;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. public class CpsUpperNode extends AbstractCpsObject {
  5. private ArrayList<AbstractCpsObject> nodes;
  6. private ArrayList<CpsEdge> nodeEdges;
  7. private ArrayList<CpsEdge> oldEdges;
  8. private HashMap<Integer, Integer> nodesIdx;
  9. public CpsUpperNode(String nodeName) {
  10. super(nodeName);
  11. this.setConnections(new ArrayList<CpsEdge>());
  12. this.setImage("/Images/upper_node.png");
  13. this.setSav("CVS");
  14. this.setID(IdCounter.nextId());
  15. this.setNodes(new ArrayList<AbstractCpsObject>());
  16. this.setNodeEdges(new ArrayList<CpsEdge>());
  17. this.setOldEdges(new ArrayList<CpsEdge>());
  18. this.setNodesIdx(new HashMap<Integer, Integer>());
  19. // TODO Auto-generated constructor stub
  20. }
  21. /**
  22. * @return the nodes
  23. */
  24. public ArrayList<AbstractCpsObject> getNodes() {
  25. return nodes;
  26. }
  27. /**
  28. * @param nodes
  29. * the nodes to set
  30. */
  31. public void setNodes(ArrayList<AbstractCpsObject> nodes) {
  32. this.nodes = nodes;
  33. }
  34. /**
  35. * @return the nodeEdges
  36. */
  37. public ArrayList<CpsEdge> getNodeEdges() {
  38. return nodeEdges;
  39. }
  40. /**
  41. * @param nodeEdges
  42. * the nodeEdges to set
  43. */
  44. public void setNodeEdges(ArrayList<CpsEdge> nodeEdges) {
  45. this.nodeEdges = nodeEdges;
  46. }
  47. /**
  48. * @return the oldEdges
  49. */
  50. public ArrayList<CpsEdge> getOldEdges() {
  51. return oldEdges;
  52. }
  53. /**
  54. * @param oldEdges
  55. * the oldEdges to set
  56. */
  57. public void setOldEdges(ArrayList<CpsEdge> oldEdges) {
  58. this.oldEdges = oldEdges;
  59. }
  60. /**
  61. * @return the nodesIdx
  62. */
  63. public HashMap<Integer, Integer> getNodesIdx() {
  64. return nodesIdx;
  65. }
  66. /**
  67. * @param nodesIdx
  68. * the nodesIdx to set
  69. */
  70. public void setNodesIdx(HashMap<Integer, Integer> nodesIdx) {
  71. this.nodesIdx = nodesIdx;
  72. }
  73. public ArrayList<HolonObject> getNumHolonObj() {
  74. ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
  75. for (AbstractCpsObject temp : getNodes()) {
  76. if (temp instanceof HolonObject) {
  77. onlyHolonObj.add((HolonObject) temp);
  78. }
  79. }
  80. return onlyHolonObj;
  81. }
  82. public ArrayList<HolonSwitch> getNumSwitches() {
  83. ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
  84. for (AbstractCpsObject temp : getNodes()) {
  85. if (temp instanceof HolonSwitch) {
  86. onlySwitsches.add((HolonSwitch) temp);
  87. }
  88. }
  89. return onlySwitsches;
  90. }
  91. public ArrayList<CpsUpperNode> getNumUpperNodes() {
  92. ArrayList<CpsUpperNode> onlyUpperNodes = new ArrayList<CpsUpperNode>();
  93. for (AbstractCpsObject temp : getNodes()) {
  94. if (temp instanceof CpsUpperNode) {
  95. onlyUpperNodes.add((CpsUpperNode) temp);
  96. }
  97. }
  98. return onlyUpperNodes;
  99. }
  100. public AbstractCpsObject searchObj(int ID) {
  101. AbstractCpsObject result = null;
  102. for (AbstractCpsObject obj : getNodes()) {
  103. if (obj.getID() == ID) {
  104. result = obj;
  105. break;
  106. }
  107. }
  108. return result;
  109. }
  110. }