123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package ui.model;
- import java.util.ArrayList;
- import java.util.stream.Stream;
- import classes.Node;
- import jdk.jfr.Unsigned;
- import classes.GroupNode;
- import classes.HolonElement;
- import classes.Flexibility;
- import ui.model.DecoratedHolonObject.HolonObjectState;
- /**
- * For the @VisualRepresentationalState only.
- *
- * @author Tom
- *
- */
- public class DecoratedGroupNode {
- private GroupNode model;
- private ArrayList<Supplier> supplierList;
- private ArrayList<Passiv> passivList;
- private ArrayList<Consumer> consumerList;
- private ArrayList<Node> nodeList;
- /**
- * Cables that only exist on that group node. From a object in that group node
- * to a object in that group Node. Not exit the group node (a layer down).
- */
- private ArrayList<DecoratedCable> internCableList;
- /**
- * Cables that exit this group node (a Layer Up). From a object in this group
- * node to a object in a upper layer.
- */
- private ArrayList<ExitCable> exitCableList;
- private ArrayList<DecoratedSwitch> switchList;
- private ArrayList<DecoratedGroupNode> groupNodeList;
- public DecoratedGroupNode(GroupNode model) {
- this.model = model;
- this.supplierList = new ArrayList<Supplier>();
- this.passivList = new ArrayList<Passiv>();
- this.consumerList = new ArrayList<Consumer>();
- this.nodeList = new ArrayList<Node>();
- this.internCableList = new ArrayList<DecoratedCable>();
- this.exitCableList = new ArrayList<ExitCable>();
- this.switchList = new ArrayList<DecoratedSwitch>();
- this.groupNodeList = new ArrayList<DecoratedGroupNode>();
- }
- public GroupNode getModel() {
- return model;
- }
- public ArrayList<Supplier> getSupplierList() {
- return supplierList;
- }
- public ArrayList<Passiv> getPassivList() {
- return passivList;
- }
- public ArrayList<Consumer> getConsumerList() {
- return consumerList;
- }
- public ArrayList<Node> getNodeList() {
- return nodeList;
- }
- public ArrayList<DecoratedCable> getInternCableList() {
- return internCableList;
- }
- public ArrayList<ExitCable> getExitCableList() {
- return exitCableList;
- }
- public ArrayList<DecoratedSwitch> getSwitchList() {
- return switchList;
- }
- public ArrayList<DecoratedGroupNode> getGroupNodeList() {
- return groupNodeList;
- }
- // Returns the amount of holons and count himself
- public int getAmountOfGroupNodes() {
- return 1 + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfGroupNodes()).reduce(0, Integer::sum);
- }
- public Stream<Flexibility> getFlexibilitiesStream() {
- Stream<Flexibility> flexInChildGorupNode = this.groupNodeList.stream()
- .flatMap(groupNode -> groupNode.getFlexibilitiesStream());
- Stream<Flexibility> flexInThisGorupNode = objectStream()
- .flatMap(object -> object.getModel().getElements().stream().flatMap(ele -> ele.flexList.stream()));
- return Stream.concat(flexInChildGorupNode, flexInThisGorupNode);
- }
- public Stream<DecoratedHolonObject> objectStream() {
- return Stream.concat(Stream.concat(this.consumerList.stream(), this.supplierList.stream()),
- this.passivList.stream());
- }
- // Gather Informations:
- public int getAmountOfSupplier() {
- return supplierList.size()
- + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfSupplier()).reduce(0, Integer::sum);
- }
- public int getAmountOfConsumer() {
- return consumerList.size()
- + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumer()).reduce(0, Integer::sum);
- }
- public int getAmountOfPassiv() {
- return passivList.size()
- + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfPassiv()).reduce(0, Integer::sum);
- }
- public int getAmountOfConsumerWithState(HolonObjectState state) {
- return ((int) consumerList.stream().map(con -> con.getState()).filter(rightState -> (rightState == state))
- .count())
- + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(state)).reduce(0,
- Integer::sum);
- }
- public int getAmountOfElemntsFromHolonObjects() {
- return objectStream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)
- + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfElemntsFromHolonObjects()).reduce(0,
- Integer::sum);
- }
- public PriorityCounts getPriorityCounts() {
- PriorityCounts priority = new PriorityCounts();
- objectStream().forEach(object -> object.getModel().getElements().stream().forEach(ele -> priority.Count(ele)));
- groupNodeList.stream().forEach(groupNode -> priority.Add(groupNode.getPriorityCounts()));
- return priority;
- }
- public class PriorityCounts {
- @Unsigned
- public int low, medium, high, essential;
- public void Add(PriorityCounts other) {
- low += other.low;
- medium += other.medium;
- high += other.high;
- essential += other.essential;
- }
- public void Count(HolonElement element) {
- switch (element.getPriority()) {
- case Essential:
- essential++;
- break;
- case High:
- high++;
- break;
- case Medium:
- medium++;
- break;
- case Low:
- low++;
- break;
- default:
- break;
- }
- }
- }
- public int getAmountOfAktiveElemntsFromHolonObjects() {
- return objectStream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0,
- Integer::sum)
- + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfAktiveElemntsFromHolonObjects())
- .reduce(0, Integer::sum);
- }
- public float getConsumptionFromConsumer() {
- return consumerList.stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.f, Float::sum)
- + groupNodeList.stream().map(groupNode -> groupNode.getConsumptionFromConsumer()).reduce(0.f,
- Float::sum);
- }
- public float getProductionFromSupplier() {
- return supplierList.stream().map(sup -> sup.getEnergyToSupplyNetwork()).reduce(0.f, Float::sum) + groupNodeList
- .stream().map(groupNode -> groupNode.getProductionFromSupplier()).reduce(0.f, Float::sum);
- }
- public float getAverageConsumption() {
- return getConsumptionFromConsumer() / (float) getAmountOfGroupNodes();
- }
- public float getAverageProduction() {
- return getProductionFromSupplier() / (float) getAmountOfGroupNodes();
- }
- public String toString() {
- return "GroupNode" + model.getId() + " with [Supplier:" + getAmountOfSupplier() + ", NotSupplied:"
- + getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED) + ", PartiallySupplied:"
- + getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED) + ", Supplied:"
- + getAmountOfConsumerWithState(HolonObjectState.SUPPLIED) + ", OverSupplied:"
- + getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED) + ", Passiv:" + getAmountOfPassiv()
- + "]";
- }
- }
|