DecoratedGroupNode.java 5.2 KB

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