package ui.model; import java.util.ArrayList; import classes.Node; import classes.GroupNode; import ui.model.DecoratedHolonObject.HolonObjectState; /** * For the @VisualRepresentationalState only. * @author Tom * */ public class DecoratedGroupNode { private GroupNode model; private ArrayList supplierList; private ArrayList passivList; private ArrayList consumerList; private ArrayList 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 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 exitCableList; private ArrayList switchList; private ArrayList groupNodeList; public DecoratedGroupNode(GroupNode model) { this.model = model; this.supplierList = new ArrayList(); this.passivList = new ArrayList(); this.consumerList = new ArrayList(); this.nodeList = new ArrayList(); this.internCableList = new ArrayList(); this.exitCableList = new ArrayList(); this.switchList = new ArrayList(); this.groupNodeList = new ArrayList(); } public GroupNode getModel() { return model; } public ArrayList getSupplierList() { return supplierList; } public ArrayList getPassivList() { return passivList; } public ArrayList getConsumerList() { return consumerList; } public ArrayList getNodeList() { return nodeList; } public ArrayList getInternCableList() { return internCableList; } public ArrayList getExitCableList() { return exitCableList; } public ArrayList getSwitchList() { return switchList; } public ArrayList 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); } //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 passivList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+ supplierList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+ consumerList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+ groupNodeList.stream().map(groupNode -> groupNode.getAmountOfElemntsFromHolonObjects()).reduce(0, Integer::sum); } public int getAmountOfAktiveElemntsFromHolonObjects() { return passivList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+ supplierList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+ consumerList.stream().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() + "]"; } }