DecoratedGroupNode.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package model;
  2. import java.util.ArrayList;
  3. import classes.Node;
  4. import model.DecoratedHolonObject.HolonObjectState;
  5. import classes.GroupNode;
  6. /**
  7. * For the @VisualRepresentationalState only.
  8. * @author Tom
  9. *
  10. */
  11. public class DecoratedGroupNode {
  12. private GroupNode model;
  13. private ArrayList<Supplier> supplierList;
  14. private ArrayList<Passiv> passivList;
  15. private ArrayList<Consumer> consumerList;
  16. private ArrayList<Node> nodeList;
  17. /**
  18. * Cables that only exist on that group node. From a object in that group node to a object in that group Node.
  19. * Not exit the group node (a layer down).
  20. */
  21. private ArrayList<DecoratedCable> internCableList;
  22. /**
  23. * Cables that exit this group node (a Layer Up). From a object in this group node to a object in a upper layer.
  24. */
  25. private ArrayList<ExitCable> exitCableList;
  26. private ArrayList<DecoratedSwitch> switchList;
  27. private ArrayList<DecoratedGroupNode> groupNodeList;
  28. public DecoratedGroupNode(GroupNode model) {
  29. this.model = model;
  30. this.supplierList = new ArrayList<Supplier>();
  31. this.passivList = new ArrayList<Passiv>();
  32. this.consumerList = new ArrayList<Consumer>();
  33. this.nodeList = new ArrayList<Node>();
  34. this.internCableList = new ArrayList<DecoratedCable>();
  35. this.exitCableList = new ArrayList<ExitCable>();
  36. this.switchList = new ArrayList<DecoratedSwitch>();
  37. this.groupNodeList = new ArrayList<DecoratedGroupNode>();
  38. }
  39. public GroupNode getModel() {
  40. return model;
  41. }
  42. public ArrayList<Supplier> getSupplierList() {
  43. return supplierList;
  44. }
  45. public ArrayList<Passiv> getPassivList() {
  46. return passivList;
  47. }
  48. public ArrayList<Consumer> getConsumerList() {
  49. return consumerList;
  50. }
  51. public ArrayList<Node> getNodeList() {
  52. return nodeList;
  53. }
  54. public ArrayList<DecoratedCable> getInternCableList() {
  55. return internCableList;
  56. }
  57. public ArrayList<ExitCable> getExitCableList() {
  58. return exitCableList;
  59. }
  60. public ArrayList<DecoratedSwitch> getSwitchList() {
  61. return switchList;
  62. }
  63. public ArrayList<DecoratedGroupNode> getGroupNodeList() {
  64. return groupNodeList;
  65. }
  66. //Returns the amount of holons and count himself
  67. public int getAmountOfGroupNodes() {
  68. return 1 + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfGroupNodes()).reduce(0, Integer::sum);
  69. }
  70. //Gather Informations:
  71. public int getAmountOfSupplier() {
  72. return supplierList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfSupplier()).reduce(0, Integer::sum);
  73. }
  74. public int getAmountOfConsumer() {
  75. return consumerList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumer()).reduce(0,Integer::sum);
  76. }
  77. public int getAmountOfPassiv() {
  78. return passivList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfPassiv()).reduce(0, Integer::sum);
  79. }
  80. public int getAmountOfConsumerWithState(HolonObjectState state) {
  81. return ((int) consumerList.stream().map(con -> con.getState()).filter(rightState -> (rightState == state)).count()) + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(state)).reduce(0, Integer::sum);
  82. }
  83. public int getAmountOfElemntsFromHolonObjects() {
  84. return passivList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
  85. supplierList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
  86. consumerList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
  87. groupNodeList.stream().map(groupNode -> groupNode.getAmountOfElemntsFromHolonObjects()).reduce(0, Integer::sum);
  88. }
  89. public int getAmountOfAktiveElemntsFromHolonObjects() {
  90. return passivList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
  91. supplierList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
  92. consumerList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
  93. groupNodeList.stream().map(groupNode -> groupNode.getAmountOfAktiveElemntsFromHolonObjects()).reduce(0, Integer::sum);
  94. }
  95. public float getConsumptionFromConsumer() {
  96. return consumerList.stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.f, Float::sum)+
  97. groupNodeList.stream().map(groupNode -> groupNode.getConsumptionFromConsumer()).reduce(0.f, Float::sum);
  98. }
  99. public float getProductionFromSupplier() {
  100. return supplierList.stream().map(sup -> sup.getEnergyToSupplyNetwork()).reduce(0.f, Float::sum)+
  101. groupNodeList.stream().map(groupNode -> groupNode.getProductionFromSupplier()).reduce(0.f, Float::sum);
  102. }
  103. public float getAverageConsumption() {
  104. return getConsumptionFromConsumer() / (float)getAmountOfGroupNodes();
  105. }
  106. public float getAverageProduction() {
  107. return getProductionFromSupplier() / (float)getAmountOfGroupNodes();
  108. }
  109. public String toString() {
  110. return
  111. "GroupNode" + model.getId() + " with [Supplier:" + getAmountOfSupplier()
  112. + ", NotSupplied:" + getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED)
  113. + ", PartiallySupplied:" + getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED)
  114. + ", Supplied:" + getAmountOfConsumerWithState(HolonObjectState.SUPPLIED)
  115. + ", OverSupplied:" + getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED)
  116. + ", Passiv:"+ getAmountOfPassiv() + "]";
  117. }
  118. }