Browse Source

Secure Element Access

TomTroppmann 2 years ago
parent
commit
57b2d733f2

+ 2 - 2
src/holeg/addon/Randomizer.java

@@ -228,12 +228,12 @@ public class Randomizer implements AddOn {
 				return;
 			}
 			//Randomize
-			hObject.getElements().clear();
+			hObject.clearElements();
 			int randomAmountOfElementsToAdd = Random.nextIntegerInRange(minAmountOfElements, maxAmountOfElements + 1);
 			for(int i = 0; i < randomAmountOfElementsToAdd; i++) {
 				HolonElement ele = holonElementCatalog.get(Random.nextIntegerInRange(0, holonElementCatalog.size())).createHolonElement(hObject, Random.nextDouble() < randomChance );
 				if(this.useRandomPriority) ele.setPriority(prioPanel.getPriority());
-				hObject.getElements().add(ele);				
+				hObject.add(ele);			
 			}
 			
 		});

+ 6 - 6
src/holeg/algorithm/binary/BaseLine.java

@@ -296,7 +296,7 @@ public class BaseLine implements AddOn {
 				consumer:
 				for(HolonObject con: conList) {
 					//println("Consumer" + con);
-					List<HolonElement> sortedElementList = con.getElements().stream().filter(ele -> ele.active && ele.isConsumer()).sorted((a,b) -> -Float.compare(-a.getActualEnergy(), -b.getActualEnergy())).collect(Collectors.toList());
+					List<HolonElement> sortedElementList = con.getElements().filter(ele -> ele.active && ele.isConsumer()).sorted((a,b) -> -Float.compare(-a.getActualEnergy(), -b.getActualEnergy())).collect(Collectors.toList());
 					for(HolonElement element: sortedElementList) {
 						float elementConsumption = -element.getActualEnergy();
 						if(elementConsumption <= difference) {
@@ -352,10 +352,10 @@ public class BaseLine implements AddOn {
 	private void rollOutNodes(Stream<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
 		nodes.forEach(aCps -> {
 			if (aCps instanceof HolonObject hO) {
-				for (HolonElement hE : hO.getElements()) {
+				hO.getElements().forEach(hE -> {
 					positionToInit.add(hE.active);
-					access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
-				}
+					access.put(positionToInit.size() - 1 , new AccessWrapper(hE));					
+				});
 				objectList.add(hO);
 			}
 			else if (aCps instanceof HolonSwitch sw) {
@@ -373,10 +373,10 @@ public class BaseLine implements AddOn {
 	
 	private void rollOutGroupNode (GroupNode groupNode, List<Boolean> positionToInit, int timeStep) {
 		groupNode.getAllHolonObjectsRecursive().forEach(hObject -> {
-			for (HolonElement hE : hObject.getElements()) {
+			hObject.getElements().forEach(hE -> {
 				positionToInit.add(hE.active);
 				access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
-			}
+			});
 			objectList.add(hObject);
 		});
 		groupNode.getAllSwitchObjectsRecursive().forEach(sw -> {

+ 13 - 10
src/holeg/algorithm/example/DemoAlgo.java

@@ -294,11 +294,14 @@ public class DemoAlgo implements AddOn {
 			try {
 				//Schalte Slow das Windrad Ein
 				if(windrad == null)return;
-				for(int i = 0; i< windrad.getNumberOfElements(); i++) {
-					windrad.getElements().get(i).active = true;
-					TimeUnit.MILLISECONDS.sleep(waitDurationWindradStep);
+				windrad.getElements().forEach(hE -> {
+					hE.active = true;
+					try {
+						TimeUnit.MILLISECONDS.sleep(waitDurationWindradStep);
+					} catch (InterruptedException e) {
+					}
 					updateVisual();
-				}
+				});
 				TimeUnit.MILLISECONDS.sleep(waitDurationEnd);
 			} catch (InterruptedException e) {
 			}
@@ -315,7 +318,7 @@ public class DemoAlgo implements AddOn {
 		
 		private void deactivateWindrad() {
 			if(windrad == null)return;
-			windrad.getElements().stream().forEach(ele -> ele.active = false);
+			windrad.getElements().forEach(ele -> ele.active = false);
 		}
 		private void setHolonElemntsAktiv(int actualIteration) {
 			for(int i = 0;i<access.size();i++) {
@@ -356,10 +359,10 @@ public class DemoAlgo implements AddOn {
 		private void rollOutNodes(Stream<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
 			nodes.forEach(aCps -> {
 				if (aCps instanceof HolonObject hO) {
-					for (HolonElement hE : hO.getElements()) {
+					hO.getElements().forEach(hE -> {
 						positionToInit.add(hE.active);
 						access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
-					}
+					});
 					objectList.add(hO);
 				}
 				else if (aCps instanceof HolonSwitch sw) {
@@ -377,10 +380,10 @@ public class DemoAlgo implements AddOn {
 		
 		private void rollOutGroupNode (GroupNode groupNode, List<Boolean> positionToInit, int timeStep) {
 			groupNode.getAllHolonObjectsRecursive().forEach(hObject -> {
-				for (HolonElement hE : hObject.getElements()) {
+				hObject.getElements().forEach(hE -> {
 					positionToInit.add(hE.active);
-					access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
-				}
+					access.put(positionToInit.size() - 1 , new AccessWrapper(hE));					
+				});
 				objectList.add(hObject);
 			});
 			groupNode.getAllSwitchObjectsRecursive().forEach(sw -> {

+ 7 - 7
src/holeg/algorithm/example/FlexExample.java

@@ -435,9 +435,9 @@ public class FlexExample implements AddOn {
 		}
 		private Set<HolonElement> createListOfAllHolonElemnts(DecoratedNetwork net) {
 			Set<HolonElement> allHolonElemntsInThisNetwork = new HashSet<HolonElement>();
-			allHolonElemntsInThisNetwork.addAll(net.getConsumerList().stream().flatMap(con -> con.getModel().getElements().stream()).collect(Collectors.toList()));
-			allHolonElemntsInThisNetwork.addAll(net.getConsumerSelfSuppliedList().stream().flatMap(con -> con.getModel().getElements().stream()).collect(Collectors.toList()));
-			allHolonElemntsInThisNetwork.addAll(net.getSupplierList().stream().flatMap(con -> con.getModel().getElements().stream()).collect(Collectors.toList()));
+			allHolonElemntsInThisNetwork.addAll(net.getConsumerList().stream().flatMap(con -> con.getModel().getElements()).collect(Collectors.toList()));
+			allHolonElemntsInThisNetwork.addAll(net.getConsumerSelfSuppliedList().stream().flatMap(con -> con.getModel().getElements()).collect(Collectors.toList()));
+			allHolonElemntsInThisNetwork.addAll(net.getSupplierList().stream().flatMap(con -> con.getModel().getElements()).collect(Collectors.toList()));
 			return allHolonElemntsInThisNetwork;
 		}
 
@@ -480,10 +480,10 @@ public class FlexExample implements AddOn {
 		private void rollOutNodes(Stream<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
 			nodes.forEach(aCps -> {
 				if (aCps instanceof HolonObject hO) {
-					for (HolonElement hE : hO.getElements()) {
+					hO.getElements().forEach(hE -> {
 						positionToInit.add(hE.active);
 						access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
-					}
+					});
 					objectList.add(hO);
 				}
 				else if (aCps instanceof HolonSwitch sw) {
@@ -501,10 +501,10 @@ public class FlexExample implements AddOn {
 		
 		private void rollOutGroupNode (GroupNode groupNode, List<Boolean> positionToInit, int timeStep) {
 			groupNode.getAllHolonObjectsRecursive().forEach(hObject -> {
-				for (HolonElement hE : hObject.getElements()) {
+				hObject.getElements().forEach(hE -> {
 					positionToInit.add(hE.active);
 					access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
-				}
+				});
 				objectList.add(hObject);
 			});
 			groupNode.getAllSwitchObjectsRecursive().forEach(sw -> {

+ 1 - 1
src/holeg/algorithm/objective_function/Evaluation.java

@@ -87,7 +87,7 @@ public class Evaluation {
 	private static double inactiveHolonElementPenalty(HolonObject obj) {
 		float result = 0;
 		int activeElements = obj.getNumberOfActiveElements();
-		int maxElements = obj.getElements().size();
+		int maxElements = (int)obj.getElements().count();
 		
 		//result = (float) Math.pow((maxElements -activeElements),2)*10;
 		result = (float) Math.pow(5, 4* ( (float) maxElements - (float) activeElements)/ (float) maxElements) - 1;

+ 9 - 8
src/holeg/api/AlgorithmFrameworkFlex.java

@@ -815,10 +815,10 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 				accessKillSwitch.put(hObject, killSwitchAccess);					
 			}
 			if(this.algoUseElements) {
-				for (HolonElement hE : hObject.getElements()) {
+				hObject.getElements().forEach(hE -> {
 					positionToInit.add(hE.active);
 					access.add(new AccessWrapper(hE, killSwitchAccess));
-				}					
+				});
 			}
 		});
 		
@@ -1176,9 +1176,9 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 			type = AccessType.KillSwitch;
 			this.hObject = hObject;
 			intialStatesOfElementForKilllSwitch = new ArrayList<Boolean>();
-			for(HolonElement hE: hObject.getElements()) {
+			hObject.getElements().forEach(hE -> {
 				intialStatesOfElementForKilllSwitch.add(hE.active);
-			}
+			});
 		}
 		public AccessWrapper(HolonSwitch hSwitch){
 			type = AccessType.Switch;
@@ -1215,12 +1215,13 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 					break;
 				case KillSwitch:
 					if(state) {
-						for (HolonElement hE : hObject.getElements()) {
+						hObject.getElements().forEach(hE -> {
 							hE.active = false;
-						}						
+						});
 					}else {
-						for(int i = 0; i < hObject.getElements().size(); i++) {
-							hObject.getElements().get(i).active = intialStatesOfElementForKilllSwitch.get(i);
+						List<HolonElement> eleList = hObject.getElements().toList();
+						for(int i = 0; i < eleList.size(); i++) {
+							eleList.get(i).active = intialStatesOfElementForKilllSwitch.get(i);
 						}
 					}
 					break;

+ 3 - 3
src/holeg/api/TopologieAlgorithmFramework.java

@@ -1148,7 +1148,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			if(this.state !=  state) {
 				this.state = state;
 				if(state > 0) {
-					wildcard.getElements().clear();
+					wildcard.clearElements();
 					HolonObject hO = (HolonObject)accessIntegerToWildcard.get(state);
 					if(hO == null) {
 						console.println("null set state(" + state + ")");
@@ -1158,7 +1158,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 						}else {
 							wildcard.setName("Wildcard");
 						}
-						wildcard.getElements().addAll(hO.getElements());
+						wildcard.add(hO.getElements().toList());
 						wildcard.setImage(hO.getImage());
 					}
 				}else {
@@ -1170,7 +1170,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			state = 0;
 			wildcard.setName("Wildcard");
 			wildcard.setImage("/images/canvas/home.png");
-			wildcard.getElements().clear();
+			wildcard.clearElements();
 		}
 		
 		public String toString() {

+ 66 - 62
src/holeg/model/HolonObject.java

@@ -2,7 +2,9 @@ package holeg.model;
 
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
+import java.util.stream.Stream;
 
 
 
@@ -36,7 +38,7 @@ public class HolonObject extends AbstractCanvasObject {
     public HolonObject(HolonObject obj) {
         super(obj);
         for(HolonElement ele : obj.elements) {
-        	this.addElement(new HolonElement(ele));
+        	this.add(new HolonElement(ele));
         }
     }
 
@@ -53,33 +55,43 @@ public class HolonObject extends AbstractCanvasObject {
      *
      * @return the elements ArrayList
      */
-    public List<HolonElement> getElements() {
-        return elements;
+    public Stream<HolonElement> getElements() {
+        return elements.stream();
     }
     
-	public void setElements(List<HolonElement> list) {
-		this.elements = list;
-	}
-    
-    
-    
+    public void clearElements() {
+    	elements.clear();
+    }
 
     /**
      * adds an Element to the Object.
      *
      * @param element the Element to add
      */
-    public void addElement(HolonElement element) {
+    public void add(HolonElement element) {
         elements.add(element);
         element.parentObject = this;
     }
     
+    /**
+     * adds an Element to the Object.
+     *
+     * @param element the Element to add
+     */
+    public void add(Collection<HolonElement> elements) {
+    	for(HolonElement hE : elements) {
+    		hE.parentObject = this;    		
+    	}
+    	this.elements.addAll(elements);
+    }
+    
+    
     /**
      * remove an Element to the Object.
      *
      * @param element the Element to add
      */
-    public void removeElement(HolonElement element) {
+    public void remove(HolonElement element) {
         elements.remove(element);
         element.parentObject = null;
     }
@@ -88,40 +100,7 @@ public class HolonObject extends AbstractCanvasObject {
     	HolonElement ele = elements.remove(index);
     	ele.parentObject = null;
 	}
-
-  
-    /*
-     * STATE
-     */
-    
     
-    private float actualEnergy;
-    
-    
-    /** 
-     * This Method returns the Energy of a HolonObject. Its sums all Energies from the HolonElements of the HolonObject that are ACTIVE.
-     * If the HolonObject have no HolonElement its return 0;
-     * Is the returned Energy negative then the HolonObject need Energy because its consuming HolonElements need more Energy then the producing HolonElements.
-     * Is the returned Energy positive its reversed.
-     * @param timestep is the TimeStep to compare the HolonElements.
-     * @return The Energy of the HolonObject.
-     */
-    public void calculateEnergy(int timestep)
-    {
-    	elements.forEach(ele -> ele.calculateState(timestep));
-    	actualEnergy = elements.stream().map(element -> element.getActualEnergy()).reduce(0.0f, Float::sum);
-    }
-    
-    
-    public float getActualEnergy()
-    {
-    	return actualEnergy;
-    }
-
-    
-    
-    
-    //New Methods:
     /**
      * This Method returns the smallest consuming HolonElement that is ACTIVE.
      * If the HolonObject has no Consumer its return null. 
@@ -149,7 +128,7 @@ public class HolonObject extends AbstractCanvasObject {
     public float getMaximumConsumingElementEnergy(){
     	return elements.stream().filter(element -> element.getActualEnergy() < 0 ).map(element -> -element.getActualEnergy()).max((lhs,rhs) ->Float.compare(lhs, rhs)).orElse(0.0f);
     }
-
+    
     
     public float getMaximumProductionPossible() {
     	return elements.stream().filter(element -> element.getEnergy() > 0).map(element -> element.getEnergy()).reduce(0.0f, Float::sum);
@@ -158,10 +137,6 @@ public class HolonObject extends AbstractCanvasObject {
     	return elements.stream().filter(element -> element.getEnergy() < 0).map(element -> -element.getEnergy()).reduce(0.0f, Float::sum);
     }
     
-    
-    
-    
-    
     /** 
      * This Method returns the Energy that all HolonElements from the HolonObject produce by itself. Its sums all Energies from the HolonElements of the HolonObject that are ACTIVE and are Producer.
      * If the HolonObject have no HolonElement its return 0;
@@ -197,8 +172,49 @@ public class HolonObject extends AbstractCanvasObject {
     	return (int) elements.stream().filter(element ->  element.getActualEnergy() > 0).count();
     }
     
+    public int getNumberOfActiveElements() {
+    	return (int) elements.stream().filter(ele -> ele.active).count();
+    }
+    
+    public int getNumberOfInActiveElements() {
+    	return (int) elements.stream().filter(ele -> !ele.active).count();
+    }
+    
+    public int getNumberOfElements() {
+    	return elements.size();
+    }
+   
+    /*
+     * STATE
+     */
+    private float actualEnergy;
+    
+    
+    /** 
+     * This Method returns the Energy of a HolonObject. Its sums all Energies from the HolonElements of the HolonObject that are ACTIVE.
+     * If the HolonObject have no HolonElement its return 0;
+     * Is the returned Energy negative then the HolonObject need Energy because its consuming HolonElements need more Energy then the producing HolonElements.
+     * Is the returned Energy positive its reversed.
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The Energy of the HolonObject.
+     */
+    public void calculateEnergy(int timestep)
+    {
+    	elements.forEach(ele -> ele.calculateState(timestep));
+    	actualEnergy = elements.stream().map(element -> element.getActualEnergy()).reduce(0.0f, Float::sum);
+    }
+    
+    
+    public float getActualEnergy()
+    {
+    	return actualEnergy;
+    }
 
-
+    
+    
+    
+    
+    
 
 
 
@@ -227,18 +243,6 @@ public class HolonObject extends AbstractCanvasObject {
     }
     
 
-	public int getNumberOfActiveElements() {
-		return (int) elements.stream().filter(ele -> ele.active).count();
-	}
-	
-	public int getNumberOfInActiveElements() {
-		return (int) elements.stream().filter(ele -> !ele.active).count();
-	}
-	
-	public int getNumberOfElements() {
-		return elements.size();
-	}
-
 
 
 	

+ 18 - 17
src/holeg/ui/controller/CategoryController.java

@@ -46,22 +46,22 @@ public class CategoryController {
 				"/images/canvas/power_plant.png");
 		HolonObject house = addNewHolonObject(building, "House", new ArrayList<HolonElement>(), "/images/canvas/home.png");
 		addNewHolonSwitch(component, "Switch", "/images/canvas/switch_on.png");
-		powerPlant.addElement(new HolonElement(null, "Power", 10000));
+		powerPlant.add(new HolonElement(null, "Power", 10000));
 		energy.getObjects().add(powerPlant);
 	
-		house.addElement(new HolonElement(null, "TV", -250));
-		house.addElement(new HolonElement(null, "TV", -250));
-		house.addElement(new HolonElement(null, "Fridge", -500));
-		house.addElement(new HolonElement(null, "Radio", -100));
-		house.addElement(new HolonElement(null, "PC", -250));
-		house.addElement(new HolonElement(null, "PC", -250));
-		house.addElement(new HolonElement(null, "PC", -250));
-		house.addElement(new HolonElement(null, "Light", -50));
-		house.addElement(new HolonElement(null, "Light", -50));
-		house.addElement(new HolonElement(null, "Light", -50));
-		house.addElement(new HolonElement(null, "Light", -50));
-		house.addElement(new HolonElement(null, "Light", -50));
-		house.addElement(new HolonElement(null, "Solar Panel", 300));
+		house.add(new HolonElement(null, "TV", -250));
+		house.add(new HolonElement(null, "TV", -250));
+		house.add(new HolonElement(null, "Fridge", -500));
+		house.add(new HolonElement(null, "Radio", -100));
+		house.add(new HolonElement(null, "PC", -250));
+		house.add(new HolonElement(null, "PC", -250));
+		house.add(new HolonElement(null, "PC", -250));
+		house.add(new HolonElement(null, "Light", -50));
+		house.add(new HolonElement(null, "Light", -50));
+		house.add(new HolonElement(null, "Light", -50));
+		house.add(new HolonElement(null, "Light", -50));
+		house.add(new HolonElement(null, "Light", -50));
+		house.add(new HolonElement(null, "Solar Panel", 300));
 		building.getObjects().add(house);
 		OnCategoryChanged.broadcast();
 	}
@@ -118,8 +118,8 @@ public class CategoryController {
 			i++;
 		}
 		if(updateElementSaves && object instanceof HolonObject hO&&hO.getElements()!=null){
-			for(HolonElement e: hO.getElements()){
-				e.setSaving(new SimpleEntry<String,String>(e.getSaving().getKey(), name));
+			for(HolonElement hE : hO.getElements().toList()) {
+				hE.setSaving(new SimpleEntry<String,String>(hE.getSaving().getKey(), name));				
 			}
 		}
 		category.getObjects().add(object);
@@ -140,7 +140,8 @@ public class CategoryController {
 	public HolonObject addNewHolonObject(Category category, String object, List<HolonElement> list, String image) {
 		HolonObject obj = new HolonObject(object);
 		obj.setImage(image);
-		obj.setElements(list);
+		obj.clearElements();
+		obj.add(list);
 		obj.setSav(category.getName());
 		addObject(category, obj);
 		return obj;

+ 1 - 1
src/holeg/ui/controller/ClipboardController.java

@@ -242,7 +242,7 @@ public class ClipboardController {
         // lookup that object
         HolonObject obj = (HolonObject) objDispatch.get(stored);
         // add it
-        obj.addElement(ele);
+        obj.add(ele);
         // store element also inside a table
         eleDispatch.put(ele.getId(), ele);
     }

+ 2 - 2
src/holeg/ui/controller/LoadController.java

@@ -260,7 +260,7 @@ public class LoadController {
         cgC.findCategoryWithName(ele.getSaving().getKey()).ifPresent(cat -> {
         	cat.findObjectWithName(ele.getSaving().getValue()).ifPresent(obj -> {
         		HolonObject hObject = (HolonObject) obj;
-        		hObject.addElement(ele);
+        		hObject.add(ele);
         	});
         });
         
@@ -338,7 +338,7 @@ public class LoadController {
         // lookup that object
         HolonObject hObject = (HolonObject) objDispatch.get(stored);
         // add it
-        hObject.addElement(ele);
+        hObject.add(ele);
         ele.parentObject = hObject;
         // store element also inside a table
         eleDispatch.put(ele.getId(), ele);

+ 1 - 1
src/holeg/ui/controller/SaveController.java

@@ -246,7 +246,7 @@ public class SaveController {
         JsonObject temp = new JsonObject();
         String key = null;
         // forall elements store them into json and include the id of the object
-        for (HolonElement ele : ((HolonObject) obj).getElements()) {
+        for (HolonElement ele : ((HolonObject) obj).getElements().toList()) {
             temp.add("properties", GuiSettings.gson.toJsonTree(ele));
             temp.add("ID", new JsonPrimitive(obj.getId()));
             temp.add("FlexList", GuiSettings.gson.toJsonTree(ele.flexList,  new TypeToken<List<Flexibility>>() {

+ 3 - 3
src/holeg/ui/model/DecoratedGroupNode.java

@@ -87,7 +87,7 @@ public class DecoratedGroupNode {
 				.flatMap(groupNode -> groupNode.getFlexibilitiesStream());
 
 		Stream<Flexibility> flexInThisGorupNode = objectStream()
-				.flatMap(object -> object.getModel().getElements().stream().flatMap(ele -> ele.flexList.stream()));
+				.flatMap(object -> object.getModel().getElements().flatMap(ele -> ele.flexList.stream()));
 
 		return Stream.concat(flexInChildGorupNode, flexInThisGorupNode);
 	}
@@ -121,14 +121,14 @@ public class DecoratedGroupNode {
 	}
 
 	public int getAmountOfElemntsFromHolonObjects() {
-		return objectStream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)
+		return objectStream().map(object -> (int)object.getModel().getElements().count()).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)));
+		objectStream().forEach(object -> object.getModel().getElements().forEach(ele -> priority.Count(ele)));
 		groupNodeList.stream().forEach(groupNode -> priority.Add(groupNode.getPriorityCounts()));
 		return priority;
 	}

+ 4 - 4
src/holeg/ui/model/DecoratedNetwork.java

@@ -388,10 +388,10 @@ public class DecoratedNetwork {
 	// HelperFunction
 
 	public Stream<HolonElement> getElementStream() {
-		return Stream.concat(consumerList.stream().flatMap(con -> con.getModel().getElements().stream()),
-				Stream.concat(consumerSelfSuppliedList.stream().flatMap(con -> con.getModel().getElements().stream()),
-						Stream.concat(supplierList.stream().flatMap(con -> con.getModel().getElements().stream()),
-								passivNoEnergyList.stream().flatMap(con -> con.getModel().getElements().stream()))));
+		return Stream.concat(consumerList.stream().flatMap(con -> con.getModel().getElements()),
+				Stream.concat(consumerSelfSuppliedList.stream().flatMap(con -> con.getModel().getElements()),
+						Stream.concat(supplierList.stream().flatMap(con -> con.getModel().getElements()),
+								passivNoEnergyList.stream().flatMap(con -> con.getModel().getElements()))));
 	}
 
 	/**

+ 2 - 2
src/holeg/ui/model/Model.java

@@ -128,11 +128,11 @@ public class Model {
 
 
     public List<HolonElement> getAllHolonElements() {
-    	return canvas.getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements().stream()).collect(Collectors.toList());
+    	return canvas.getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements()).collect(Collectors.toList());
     }
     
     public List<Flexibility> getAllFlexibilities() {
-    	return canvas.getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements().stream().flatMap(ele -> ele.flexList.stream())).collect(Collectors.toList());
+    	return canvas.getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements().flatMap(ele -> ele.flexList.stream())).collect(Collectors.toList());
     }
     
     public void reset() {

+ 0 - 2
src/holeg/ui/view/canvas/AbstractCanvas.java

@@ -22,7 +22,6 @@ import javax.swing.Timer;
 import holeg.model.AbstractCanvasObject;
 import holeg.model.Edge;
 import holeg.model.GroupNode;
-import holeg.model.HolonElement;
 import holeg.model.HolonObject;
 import holeg.model.Node;
 import holeg.ui.controller.Control;
@@ -77,7 +76,6 @@ public abstract class AbstractCanvas extends JPanel {
 	boolean toolTip; // Tooltip on or off
 	Vec2i toolTipPos = new Vec2i(); // Tooltip Position
 	String toolTipText = "";
-	List<HolonElement> dataSelected = new ArrayList<>();
 	protected Set<AbstractCanvasObject> tempSelected = new HashSet<>();
 	boolean showConnectionInformation;
 	boolean dragging = false; // for dragging

+ 0 - 6
src/holeg/ui/view/canvas/Canvas.java

@@ -597,12 +597,6 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 						}
 
 					}
-
-					// If drawing an Edge (CTRL down)
-					if (tempCps.getClass() == HolonObject.class) {
-						HolonObject tempObj = ((HolonObject) tempCps);
-						dataSelected = tempObj.getElements();
-					}
 					if (e.isShiftDown()) {
 						drawEdge = true;
 						dragging = false;

+ 1 - 1
src/holeg/ui/view/dialog/AddElementPopUp.java

@@ -160,7 +160,7 @@ public class AddElementPopUp extends JDialog {
 	 */
 	private void okAction() {
 		boolean repeated = false;
-		for (HolonElement e :  tempCps.getElements()) {
+		for (HolonElement e :  tempCps.getElements().toList()) {
 			if (elementName.getText().equals(e.getName())&&(hl == null || hl.getId()!=e.getId())) {
 				repeated = true;
 				break;

+ 3 - 3
src/holeg/ui/view/dialog/AddObjectPopUp.java

@@ -195,9 +195,9 @@ public class AddObjectPopUp extends JDialog {
 			}
 		}
 		if (edit) {
-			for (HolonElement e : ((HolonObject) obj).getElements()) {
-				addElement(e);
-			}
+			((HolonObject) obj).getElements().forEach(hE -> {
+				addElement(hE);
+			});
 		}
 		{
 			JButton btnNewButton = new JButton("Delete Element");

+ 8 - 8
src/holeg/ui/view/dialog/CreateTemplatePopUp.java

@@ -205,10 +205,10 @@ public class CreateTemplatePopUp extends JDialog {
 		/**
 		 * Add Elements to List
 		 */
-		for (HolonElement he : template.getElements())
-			listModel.addElement(he.getName()
-					+ ": " + he.getEnergy() + "U");
-
+		template.getElements().forEach(hE -> {
+			listModel.addElement(hE.getName()
+					+ ": " + hE.getEnergy() + "U");			
+		});
 		/**
 		 * Add ScrollPane to List
 		 */
@@ -299,7 +299,7 @@ public class CreateTemplatePopUp extends JDialog {
 		controller.findCategoryWithName(choice
 				.getItem(choice.getSelectedIndex())).ifPresent(cat -> {
 					controller.addObject(cat, template.getName(),
-							template.getElements(), template.getImage());
+							template.getElements().toList(), template.getImage());
 				});
 		this.dispose();
 	}
@@ -315,7 +315,7 @@ public class CreateTemplatePopUp extends JDialog {
 		if (he != null) {
 			listModel.addElement(he.getName()
 					+ ": " + he.getEnergy() + "U");
-			template.addElement(he);
+			template.add(he);
 			he.setSaving(new SimpleEntry<>(category, textField_name.getText()));
 		}
 	}
@@ -341,7 +341,7 @@ public class CreateTemplatePopUp extends JDialog {
 		
 		AddElementPopUp popUp = new AddElementPopUp(parent);
 		popUp.setActualHolonObject(template);
-		popUp.setElement(template.getElements().get(index));
+		popUp.setElement(template.getElements().toList().get(index));
 		popUp.setVisible(true);
 		HolonElement he = popUp.getElement();
 		if (he != null) {
@@ -349,7 +349,7 @@ public class CreateTemplatePopUp extends JDialog {
 			listModel.addElement(he.getName()
 					+ ": " + he.getEnergy() + "U");
 			template.removeElement(index);
-			template.addElement(he);
+			template.add(he);
 			he.setSaving(new SimpleEntry<>(category, textField_name.getText()));
 		}
 	}

+ 6 - 6
src/holeg/ui/view/information/FilterableGroupNode.java

@@ -110,7 +110,7 @@ public class FilterableGroupNode {
 				.flatMap(groupNode -> groupNode.getFlexibilitiesStream(stateFilter, priorityFilter));
 
 		Stream<Flexibility> flexInThisGorupNode = objectStream().filter(stateFilter).flatMap(object -> object.getModel()
-				.getElements().stream().filter(priorityFilter).flatMap(ele -> ele.flexList.stream()));
+				.getElements().filter(priorityFilter).flatMap(ele -> ele.flexList.stream()));
 
 		return Stream.concat(flexInChildGorupNode, flexInThisGorupNode);
 	}
@@ -146,7 +146,7 @@ public class FilterableGroupNode {
 	public PriorityCounts getPriorityCounts(Predicate<DecoratedHolonObject> stateFilter) {
 		PriorityCounts priority = new PriorityCounts();
 		objectStream().filter(stateFilter)
-				.forEach(object -> object.getModel().getElements().stream().forEach(ele -> priority.Count(ele)));
+				.forEach(object -> object.getModel().getElements().forEach(ele -> priority.Count(ele)));
 		groupNodeList.stream().forEach(groupNode -> priority.Add(groupNode.getPriorityCounts(stateFilter)));
 		return priority;
 	}
@@ -186,7 +186,7 @@ public class FilterableGroupNode {
 	public int getAmountOfElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
 			Predicate<HolonElement> priorityFilter) {
 		return objectStream().filter(stateFilter)
-				.map(object -> (int) object.getModel().getElements().stream().filter(priorityFilter).count())
+				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
 				.reduce(0, Integer::sum)
 				+ groupNodeList.stream()
 						.map(groupNode -> groupNode.getAmountOfElementsFromHolonObjects(stateFilter, priorityFilter))
@@ -196,7 +196,7 @@ public class FilterableGroupNode {
 	public int getAmountOfAktiveElementsFromHolonObjects(Predicate<DecoratedHolonObject> stateFilter,
 			Predicate<HolonElement> priorityFilter) {
 		return objectStream().filter(stateFilter)
-				.map(object -> (int) object.getModel().getElements().stream().filter(priorityFilter).count())
+				.map(object -> (int) object.getModel().getElements().filter(priorityFilter).count())
 				.reduce(0, Integer::sum)
 				+ groupNodeList.stream().map(
 						groupNode -> groupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter))
@@ -206,7 +206,7 @@ public class FilterableGroupNode {
 	public float getConsumption(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
 		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
 				.filter(stateFilter)
-				.map(con -> con.getModel().getElements().stream()
+				.map(con -> con.getModel().getElements()
 						.filter(priorityFilter.and(ele -> ele.getActualEnergy() < 0))
 						.map(ele -> -ele.getActualEnergy()).reduce(0.0f, Float::sum))
 				.reduce(0.f, Float::sum)
@@ -217,7 +217,7 @@ public class FilterableGroupNode {
 	public float getProduction(Predicate<DecoratedHolonObject> stateFilter, Predicate<HolonElement> priorityFilter) {
 		return ((Stream<DecoratedHolonObject>) Stream.concat(this.consumerList.stream(), supplierList.stream()))
 				.filter(stateFilter)
-				.map(con -> con.getModel().getElements().stream()
+				.map(con -> con.getModel().getElements()
 						.filter(priorityFilter.and(ele -> ele.getActualEnergy() > 0))
 						.map(ele -> ele.getActualEnergy()).reduce(0.0f, Float::sum))
 				.reduce(0.f, Float::sum)

+ 5 - 5
src/holeg/ui/view/inspector/InspectorTable.java

@@ -239,7 +239,7 @@ public class InspectorTable extends JPanel {
 					.filter(obj -> obj instanceof HolonObject).reduce((prev, next) -> next)
 					.map(obj -> (HolonObject) obj);
 			last.ifPresent(obj -> {
-				obj.addElement(new HolonElement(obj, "Element", 0.0f));
+				obj.add(new HolonElement(obj, "Element", 0.0f));
 				control.calculateStateAndVisualForCurrentTimeStep();
 				updateInspectorUi();
 			});
@@ -251,7 +251,7 @@ public class InspectorTable extends JPanel {
 		duplicateButton.addActionListener(clicked -> {
 			rowPool.getBorrowedStream().forEach(row -> {
 				if (row.isSelected()) {
-					row.element.parentObject.addElement(new HolonElement(row.element));
+					row.element.parentObject.add(new HolonElement(row.element));
 				}
 			});
 			control.calculateStateAndVisualForCurrentTimeStep();
@@ -264,7 +264,7 @@ public class InspectorTable extends JPanel {
 		deleteButton.addActionListener(clicked -> {
 			rowPool.getBorrowedStream().forEach(row -> {
 				if (row.isSelected()) {
-					row.element.parentObject.removeElement(row.element);
+					row.element.parentObject.remove(row.element);
 				}
 			});
 			control.calculateStateAndVisualForCurrentTimeStep();
@@ -375,10 +375,10 @@ public class InspectorTable extends JPanel {
 	// Extract elements from a list of AbstractCanvasObjects
 	static Stream<HolonElement> extractElements(Collection<AbstractCanvasObject> toInspect) {
 		Stream<HolonElement> recursiveLayer = toInspect.stream().filter(object -> object instanceof GroupNode).flatMap(
-				obj -> ((GroupNode) obj).getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements().stream()));
+				obj -> ((GroupNode) obj).getAllHolonObjectsRecursive().flatMap(hO -> hO.getElements()));
 		Stream<HolonElement> thisLayer = toInspect.stream().filter(obj -> obj instanceof HolonObject).flatMap(obj -> {
 			HolonObject ho = (HolonObject) obj;
-			return ho.getElements().stream();
+			return ho.getElements();
 		});
 		return Stream.concat(thisLayer, recursiveLayer);
 	}

+ 8 - 8
src/holeg/ui/view/window/FlexWindow.java

@@ -418,11 +418,11 @@ public class FlexWindow extends JFrame {
 
 
 	private void expandTreeHolonObject(HolonObject hObject, DefaultMutableTreeNode root) {
-		for(HolonElement hElement: hObject.getElements()) {
-			DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(new ElementInfo(hElement));
-			expandTreeFlex(hElement, newChild);
-			root.add(newChild);
-		}
+		hObject.getElements().forEach(hE -> {
+			DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(new ElementInfo(hE));
+			expandTreeFlex(hE, newChild);
+			root.add(newChild);			
+		});
 	}
 	private void expandTreeFlex(HolonElement hElement, DefaultMutableTreeNode root) {
 		for(Flexibility flex: hElement.flexList) {
@@ -436,7 +436,7 @@ public class FlexWindow extends JFrame {
 	
 	
 	private void createDeleteDialog() {
-		Object[] allFlexes = model.getCanvas().getAllHolonObjectsRecursive().flatMap(hObject -> hObject.getElements().stream()).flatMap(hElement -> hElement.flexList.stream()).toArray(size -> new Flexibility[size]);
+		Object[] allFlexes = model.getAllFlexibilities().toArray();
 		if(allFlexes.length == 0) {
 			JOptionPane.showMessageDialog(this,
 					"No Flexibility exist.",
@@ -494,14 +494,14 @@ public class FlexWindow extends JFrame {
 		JComboBox<HolonObject> holonObjectSelector = new JComboBox<HolonObject>(comboBoxModel);
 		holonObjectSelector.setBounds(10,30, 800, 30);
 		
-		DefaultComboBoxModel<HolonElement> comboBoxModelElements = new DefaultComboBoxModel<HolonElement>( holonObjects[0].getElements().stream().toArray(size -> new HolonElement[size]));
+		DefaultComboBoxModel<HolonElement> comboBoxModelElements = new DefaultComboBoxModel<HolonElement>( holonObjects[0].getElements().toArray(size -> new HolonElement[size]));
 		JComboBox<HolonElement> holonElementSelector  = new JComboBox<HolonElement>(comboBoxModelElements);
 		holonElementSelector.setBounds(10,80, 800, 30);
 		
 		
 		holonObjectSelector.addItemListener(aListener -> {
 			if(aListener.getStateChange() == ItemEvent.SELECTED) {
-				DefaultComboBoxModel<HolonElement> newComboBoxModelElements = new DefaultComboBoxModel<HolonElement>( ((HolonObject) aListener.getItem()).getElements().stream().toArray(size -> new HolonElement[size]));
+				DefaultComboBoxModel<HolonElement> newComboBoxModelElements = new DefaultComboBoxModel<HolonElement>( ((HolonObject) aListener.getItem()).getElements().toArray(size -> new HolonElement[size]));
 				holonElementSelector.setModel(newComboBoxModelElements);
 			}
 		});