Parcourir la source

Using Java 16 Feature instanceof Pattern Matching

TomTroppmann il y a 2 ans
Parent
commit
45e5c76bee

+ 0 - 3
src/addon/RandomOfferdFlexibility.java

@@ -306,10 +306,7 @@ public class RandomOfferdFlexibility implements AddOn {
 	
 	
 	private void run() {
-		//control.getModel().getObjectsOnCanvas().stream().filter(aCps -> aCps instanceof HolonObject)
-		
 		if(control == null) {
-			System.out.println("Nothing to do");
 			return;
 		}
 		if(low.checkbox.isSelected()) low.updateCanvasToTargetAmounts();

+ 4 - 5
src/addon/Randomizer.java

@@ -248,14 +248,13 @@ public class Randomizer implements AddOn {
 	
 	private void fillObjectMap(List<AbstractCanvasObject> nodes) {
 		for (AbstractCanvasObject aCps : nodes) {
-			if (aCps instanceof HolonObject) {
-				HolonObject hO = (HolonObject) aCps;
+			if (aCps instanceof HolonObject hO) {
 				objectMap.put(hO, true);
-				
 			}
-			else if(aCps instanceof GroupNode) {
-				fillObjectMap(((GroupNode)aCps).getNodes());
+			else if(aCps instanceof GroupNode groupNpde) {
+				fillObjectMap(groupNpde.getNodes());
 			}
+			
 		}
 		
 	}

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

@@ -350,21 +350,20 @@ public class BaseLine implements AddOn {
 	 */
 	private void rollOutNodes(List<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
 		for(AbstractCanvasObject aCps : nodes) {
-			if (aCps instanceof HolonObject) {
-				for (HolonElement hE : ((HolonObject) aCps).getElements()) {
+			if (aCps instanceof HolonObject hO) {
+				for (HolonElement hE : hO.getElements()) {
 					positionToInit.add(hE.active);
 					access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
 				}
-				objectList.add((HolonObject) aCps);
+				objectList.add(hO);
 			}
-			else if (aCps instanceof HolonSwitch) {
-				HolonSwitch sw = (HolonSwitch) aCps;
+			else if (aCps instanceof HolonSwitch sw) {
 				positionToInit.add(sw.getState(timeStep));
 				switchList.add(sw);
 				access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 			}
-			else if(aCps instanceof GroupNode) {
-				rollOutNodes(((GroupNode)aCps).getNodes(), positionToInit ,timeStep );
+			else if(aCps instanceof GroupNode groupnode) {
+				rollOutNodes(groupnode.getNodes(), positionToInit ,timeStep );
 			}
 		}
 	}

+ 9 - 10
src/algorithm/example/DemoAlgo.java

@@ -354,21 +354,20 @@ public class DemoAlgo implements AddOn {
 		 */
 		private void rollOutNodes(List<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
 			for(AbstractCanvasObject aCps : nodes) {
-				if (aCps instanceof HolonObject) {
-					for (HolonElement hE : ((HolonObject) aCps).getElements()) {
+				if (aCps instanceof HolonObject hO) {
+					for (HolonElement hE : hO.getElements()) {
 						positionToInit.add(hE.active);
 						access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
 					}
-					objectList.add((HolonObject) aCps);
+					objectList.add(hO);
 				}
-				else if (aCps instanceof HolonSwitch) {
-					HolonSwitch sw = (HolonSwitch) aCps;
+				else if (aCps instanceof HolonSwitch sw) {
 					positionToInit.add(sw.getState(timeStep));
 					switchList.add(sw);
 					access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 				}
-				else if(aCps instanceof GroupNode) {
-					rollOutNodes(((GroupNode)aCps).getNodes(), positionToInit ,timeStep );
+				else if(aCps instanceof GroupNode groupnode) {
+					rollOutNodes(groupnode.getNodes(), positionToInit ,timeStep );
 				}
 			}
 		}
@@ -414,9 +413,9 @@ public class DemoAlgo implements AddOn {
 
 		private void addObjectToList(List<AbstractCanvasObject> listToSearch, List<HolonObject> listToAdd){
 			for (AbstractCanvasObject aCps : listToSearch) {
-				if (aCps instanceof HolonObject) listToAdd.add((HolonObject) aCps);
-				else if(aCps instanceof GroupNode) {
-					addObjectToList(((GroupNode)aCps).getNodes(),listToAdd);
+				if (aCps instanceof HolonObject hO) listToAdd.add(hO);
+				else if(aCps instanceof GroupNode groupNode) {
+					addObjectToList(groupNode.getNodes(),listToAdd);
 				}
 			}
 		}

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

@@ -477,21 +477,20 @@ public class FlexExample implements AddOn {
 		 */
 		private void rollOutNodes(List<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
 			for(AbstractCanvasObject aCps : nodes) {
-				if (aCps instanceof HolonObject) {
-					for (HolonElement hE : ((HolonObject) aCps).getElements()) {
+				if (aCps instanceof HolonObject hO) {
+					for (HolonElement hE : hO.getElements()) {
 						positionToInit.add(hE.active);
 						access.put(positionToInit.size() - 1 , new AccessWrapper(hE));
 					}
-					objectList.add((HolonObject) aCps);
+					objectList.add(hO);
 				}
-				else if (aCps instanceof HolonSwitch) {
-					HolonSwitch sw = (HolonSwitch) aCps;
+				else if (aCps instanceof HolonSwitch sw) {
 					positionToInit.add(sw.getState(timeStep));
 					switchList.add(sw);
 					access.put(positionToInit.size() - 1 , new AccessWrapper(sw));
 				}
-				else if(aCps instanceof GroupNode) {
-					rollOutNodes(((GroupNode)aCps).getNodes(), positionToInit ,timeStep );
+				else if(aCps instanceof GroupNode groupnode) {
+					rollOutNodes(groupnode.getNodes(), positionToInit ,timeStep );
 				}
 			}
 		}

+ 2 - 2
src/algorithm/objective_function/GraphMetrics.java

@@ -105,10 +105,10 @@ public class GraphMetrics {
 			}
 			
 			//SpecialCase for open switches
-			if(objectA instanceof HolonSwitch && !((HolonSwitch)objectA).getManualState()) {
+			if(objectA instanceof HolonSwitch sw && !sw.getManualState()) {
 				continue;
 			}
-			if(objectB instanceof HolonSwitch && !((HolonSwitch)objectB).getManualState()) {
+			if(objectB instanceof HolonSwitch sw && !sw.getManualState()) {
 				continue;
 			}
 			

+ 4 - 6
src/api/AlgorithmFrameworkFlex.java

@@ -812,8 +812,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	 */
 	private void rollOutNodes(List<AbstractCanvasObject> nodes, List<Boolean> positionToInit, int timeStep) {
 		for(AbstractCanvasObject aCps : nodes) {
-			if (aCps instanceof HolonObject) {
-				HolonObject hObject = (HolonObject) aCps;
+			if (aCps instanceof HolonObject hObject) {
 				AccessWrapper killSwitchAccess = new AccessWrapper(hObject);
 				if(this.algoUseKillSwitch) {
 					positionToInit.add(false);
@@ -827,13 +826,12 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 					}					
 				}
 			}
-			else if (aCps instanceof HolonSwitch&& algoUseSwitches) {
-				HolonSwitch sw = (HolonSwitch) aCps;
+			else if (aCps instanceof HolonSwitch sw && algoUseSwitches) {
 				positionToInit.add(sw.getState(timeStep));
 				access.add(new AccessWrapper(sw));
 			}
-			else if(aCps instanceof GroupNode) {
-				rollOutNodes(((GroupNode)aCps).getNodes(), positionToInit ,timeStep );
+			else if(aCps instanceof GroupNode groupnode) {
+				rollOutNodes(groupnode.getNodes(), positionToInit ,timeStep );
 			}
 		}
 	}

+ 8 - 12
src/api/TopologieAlgorithmFramework.java

@@ -790,8 +790,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	 */
 	private void generateAccess(List<AbstractCanvasObject> nodes, GroupNode groupnode) {
 		for(AbstractCanvasObject aCps : nodes) {
-			if(aCps instanceof HolonObject) {
-				HolonObject hO = (HolonObject) aCps;
+			if(aCps instanceof HolonObject hO) {
 				accessIntToObject.put(++countForAccessMap, hO);
 				accessObjectToInt.put(hO, countForAccessMap);
 				if(hO.getName().contains("Wildcard")) {
@@ -801,24 +800,22 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 					accessGroupNode.put(hO, groupnode);
 				}
 			}
-			if(aCps instanceof HolonSwitch) {
-				HolonSwitch hSwitch = (HolonSwitch) aCps;
+			if(aCps instanceof HolonSwitch hSwitch) {
 				accessIntToObject.put(++countForAccessMap, hSwitch);
 				accessObjectToInt.put(hSwitch, countForAccessMap);
 				if(groupnode != null) {
 					accessGroupNode.put(hSwitch, groupnode);
 				}
 			}
-			if(aCps instanceof Node) {
-				Node node = (Node) aCps;
+			if(aCps instanceof Node node) {
 				accessIntToObject.put(++countForAccessMap, node);
 				accessObjectToInt.put(node, countForAccessMap);
 				if(groupnode != null) {
 					accessGroupNode.put(node, groupnode);
 				}
 			}
-			else if(aCps instanceof GroupNode) {
-				generateAccess(((GroupNode)aCps).getNodes(), (GroupNode) aCps);
+			else if(aCps instanceof GroupNode groupNode) {
+				generateAccess(groupNode.getNodes(), groupNode);
 			}
 		}
 	}
@@ -1264,11 +1261,10 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 
 	    @Override
 	    public boolean equals(Object o) {
-	        if (!(o instanceof IndexCable)) {
-	            return false;
+	        if(o instanceof IndexCable cable) {
+	        	 return Objects.equals(cable.first, first) && Objects.equals(cable.second, second);
 	        }
-	        IndexCable p = (IndexCable) o;
-	        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
+	        return false;
 	    }
 
 	    @Override

+ 3 - 3
src/connect/ConnectHandheld.java

@@ -197,9 +197,9 @@ public class ConnectHandheld implements AddOn{
 
 		private void addObjectToList(List<AbstractCanvasObject> listToSearch, List<HolonObject> listToAdd){
 			for (AbstractCanvasObject aCps : listToSearch) {
-				if (aCps instanceof HolonObject) listToAdd.add((HolonObject) aCps);
-				else if(aCps instanceof GroupNode) {
-					addObjectToList(((GroupNode)aCps).getNodes(),listToAdd);
+				if (aCps instanceof HolonObject hO) listToAdd.add(hO);
+				else if(aCps instanceof GroupNode groupNode) {
+					addObjectToList(groupNode.getNodes(),listToAdd);
 				}
 			}
 		}

+ 3 - 3
src/connect/ConnectPhysical.java

@@ -468,9 +468,9 @@ public class ConnectPhysical implements AddOn{
 	
 	private void addObjectToList(List<AbstractCanvasObject> listToSearch, List<HolonObject> listToAdd){
 		for (AbstractCanvasObject aCps : listToSearch) {
-			if (aCps instanceof HolonObject) listToAdd.add((HolonObject) aCps);
-			else if(aCps instanceof GroupNode) {
-				addObjectToList(((GroupNode)aCps).getNodes(),listToAdd);
+			if (aCps instanceof HolonObject hO) listToAdd.add(hO);
+			else if(aCps instanceof GroupNode groupnode) {
+				addObjectToList(groupnode.getNodes(),listToAdd);
 			}
 		}
 	}

+ 6 - 10
src/connect/socket/Server.java

@@ -287,16 +287,12 @@ public class Server implements Runnable{
 			if (obj == this) {
 				return true;
 			}
-			if (!(obj instanceof HolonElementWrapper)) {
-			   return false;
-			}
-			HolonElementWrapper element = (HolonElementWrapper) obj;
-			
-			
-			
-			return this.name.compareTo(element.name) == 0 &&
-				   this.energy == element.energy &&
-				   this.enabled == element.enabled;
+			if (obj instanceof HolonElementWrapper element) {
+				return this.name.compareTo(element.name) == 0 &&
+						this.energy == element.energy &&
+						this.enabled == element.enabled;
+			}			
+			return false;
 		}
 		
 	}

+ 4 - 4
src/model/Edge.java

@@ -168,11 +168,11 @@ public class Edge {
 	
 	public float getEnergyFromConneted() {
 		float energy = 0.0f;
-		if(getA() instanceof HolonObject && ((HolonObject) getA()).getActualEnergy() > 0) {
-			energy += ((HolonObject) getA()).getActualEnergy();
+		if(getA() instanceof HolonObject hO && hO.getActualEnergy() > 0) {
+			energy += hO.getActualEnergy();
 		}
-		if(getB() instanceof HolonObject && ((HolonObject) getB()).getActualEnergy() > 0) {
-			energy += ((HolonObject) getB()).getActualEnergy();
+		if(getB() instanceof HolonObject hO && hO.getActualEnergy() > 0) {
+			energy += hO.getActualEnergy();
 		}
 		return energy;
 	}

+ 13 - 13
src/model/GroupNode.java

@@ -70,8 +70,8 @@ public class GroupNode extends AbstractCanvasObject {
 		ArrayList<AbstractCanvasObject> nodes = new ArrayList<AbstractCanvasObject>();
 		nodes.addAll(getNodes());
 		for (AbstractCanvasObject temp : getNodes()) {
-			if(temp instanceof GroupNode) {
-				nodes.addAll(((GroupNode) temp).getNodesAndGroupnodeNodes());
+			if(temp instanceof GroupNode groupnode) {
+				nodes.addAll(groupnode.getNodesAndGroupnodeNodes());
 			}
 		}
 		return nodes;
@@ -82,11 +82,11 @@ public class GroupNode extends AbstractCanvasObject {
 	public ArrayList<HolonObject> getNumHolonObj() {
 		ArrayList<HolonObject> onlyHolonObj = new ArrayList<HolonObject>();
 		for (AbstractCanvasObject temp : getNodes()) {
-			if (temp instanceof HolonObject) {
-				onlyHolonObj.add((HolonObject) temp);
+			if (temp instanceof HolonObject hO) {
+				onlyHolonObj.add(hO);
 			}
-			if(temp instanceof GroupNode) {
-				onlyHolonObj.addAll(((GroupNode) temp).getNumHolonObj());
+			if(temp instanceof GroupNode groupnode) {
+				onlyHolonObj.addAll(groupnode.getNumHolonObj());
 			}
 		}
 		return onlyHolonObj;
@@ -95,11 +95,11 @@ public class GroupNode extends AbstractCanvasObject {
 	public ArrayList<HolonSwitch> getNumSwitches() {
 		ArrayList<HolonSwitch> onlySwitsches = new ArrayList<HolonSwitch>();
 		for (AbstractCanvasObject temp : getNodes()) {
-			if (temp instanceof HolonSwitch) {
-				onlySwitsches.add((HolonSwitch) temp);
+			if (temp instanceof HolonSwitch sw) {
+				onlySwitsches.add(sw);
 			}
-			if(temp instanceof GroupNode) {
-				onlySwitsches.addAll(((GroupNode) temp).getNumSwitches());
+			if(temp instanceof GroupNode groupnode) {
+				onlySwitsches.addAll(groupnode.getNumSwitches());
 			}
 		}
 		return onlySwitsches;
@@ -108,9 +108,9 @@ public class GroupNode extends AbstractCanvasObject {
 	public ArrayList<GroupNode> getNumUpperNodes() {
 		ArrayList<GroupNode> onlyUpperNodes = new ArrayList<GroupNode>();
 		for (AbstractCanvasObject temp : getNodes()) {
-			if (temp instanceof GroupNode) {
-				onlyUpperNodes.add((GroupNode) temp);
-				onlyUpperNodes.addAll(((GroupNode) temp).getNumUpperNodes());
+			if (temp instanceof GroupNode groupnode) {
+				onlyUpperNodes.add(groupnode);
+				onlyUpperNodes.addAll(groupnode.getNumUpperNodes());
 			}
 		}
 		return onlyUpperNodes;

+ 9 - 10
src/model/HolonSwitch.java

@@ -78,23 +78,22 @@ public class HolonSwitch extends AbstractCanvasObject implements TimelineDepende
 	/**
 	 * Create a copy of an existing HolonSwitch.
 	 * 
-	 * @param obj the Object to copy
+	 * @param other the Object to copy
 	 */
-	public HolonSwitch(AbstractCanvasObject obj) {
-		super(obj);
-		HolonSwitch copyObj = (HolonSwitch) obj;
-		setLocalPeriod(copyObj.getLocalPeriod());
-		setUseLocalPeriod(copyObj.isUsingLocalPeriod());
+	public HolonSwitch(HolonSwitch other) {
+		super(other);
+		setLocalPeriod(other.getLocalPeriod());
+		setUseLocalPeriod(other.isUsingLocalPeriod());
 		activeAt = new boolean[LocalMode.STANDARD_GRAPH_ACCURACY];
-		super.setName(obj.getName());
-		setManualState(copyObj.getManualState());
+		super.setName(other.getName());
+		setManualState(other.getManualState());
 		setAutoState(true);
 		setGraphPoints(new LinkedList<Vector2Float>());
-		for (Vector2Float p : copyObj.getGraphPoints()) {
+		for (Vector2Float p : other.getGraphPoints()) {
 			this.graphPoints.add(new Vector2Float(p.getX(), p.getY()));
 		}
 		sampleGraph();
-		setManualMode(copyObj.getManualMode());
+		setManualMode(other.getManualMode());
 	}
 
 	@Override

+ 4 - 4
src/ui/controller/CanvasController.java

@@ -204,10 +204,10 @@ public class CanvasController {
 
 		// Objects
 		for (AbstractCanvasObject cps : model.getClipboradObjects()) {
-			if (cps instanceof HolonObject) {
-				tCps = new HolonObject((HolonObject) cps);
-			} else if (cps instanceof HolonSwitch) {
-				tCps = new HolonSwitch((HolonSwitch) cps);
+			if (cps instanceof HolonObject hO) {
+				tCps = new HolonObject(hO);
+			} else if (cps instanceof HolonSwitch sw) {
+				tCps = new HolonSwitch(sw);
 			} else {
 				tCps = new Node("Node");
 			}

+ 2 - 2
src/ui/controller/CategoryController.java

@@ -141,8 +141,8 @@ public class CategoryController {
 			object.setName(name);
 			i++;
 		}
-		if(updateElementSaves && object instanceof HolonObject &&((HolonObject)object).getElements()!=null){
-			for(HolonElement e: ((HolonObject)object).getElements()){
+		if(updateElementSaves && object instanceof HolonObject hO&&hO.getElements()!=null){
+			for(HolonElement e: hO.getElements()){
 				e.setSaving(new SimpleEntry<String,String>(e.getSaving().getKey(), name));
 			}
 		}

+ 9 - 11
src/ui/controller/ClipboardController.java

@@ -74,12 +74,12 @@ public class ClipboardController {
             if (u instanceof HolonObject)
                 store.elementsToJson(TYPE.CANVAS, file, u);
 
-            if (u instanceof HolonSwitch)
-                if (((HolonSwitch) u).getGraphPoints().size() != 0)
+            if (u instanceof HolonSwitch sw)
+                if (sw.getGraphPoints().size() != 0)
                     store.unitgraphToJson(GRAPHTYPE.SWITCH, file, u.getId(), ((HolonSwitch) u).getGraphPoints());
 
-            if (u instanceof GroupNode) {
-                for (AbstractCanvasObject adjacent : ((GroupNode) u).getNodes()) {
+            if (u instanceof GroupNode groupnode) {
+                for (AbstractCanvasObject adjacent : groupnode.getNodes()) {
                     queue.add(adjacent);
                 }
             }
@@ -150,8 +150,8 @@ public class ClipboardController {
             else
                 uppC.deleteObjectInUpperNode(abs, upperNode);
 
-            if (abs instanceof GroupNode)
-                cvsC.bfsNodeCleaner((GroupNode) abs);
+            if (abs instanceof GroupNode groupnode)
+                cvsC.bfsNodeCleaner(groupnode);
         }
         model.getSelectedObjects().clear();
         this.simManager.calculateStateForTimeStep(model.getActualTimeStep(), true);
@@ -389,11 +389,9 @@ public class ClipboardController {
      */
     private void clipboadDepth(AbstractCanvasObject obj) {
         //modified backtracking Algorithm no True/False
-        if (!(obj instanceof GroupNode)) {
-            model.getClipboradObjects().add(obj);
-        } else {
-            model.getClipboradObjects().add(obj);
-            for (AbstractCanvasObject abs : ((GroupNode) obj).getNodes()) {
+    	model.getClipboradObjects().add(obj);
+        if (obj instanceof GroupNode groupnode) {
+            for (AbstractCanvasObject abs : groupnode.getNodes()) {
                 clipboadDepth(abs);
             }
         }

+ 4 - 4
src/ui/controller/Control.java

@@ -332,8 +332,8 @@ public class Control {
 	 */
 	public void delCanvasObject(AbstractCanvasObject obj, boolean save) {
 		canvasController.deleteObjectOnCanvas(obj);
-		if (obj instanceof GroupNode) {
-			canvasController.bfsNodeCleaner((GroupNode) obj);
+		if (obj instanceof GroupNode groupnode) {
+			canvasController.bfsNodeCleaner(groupnode);
 		}
 		calculateStateAndVisualForCurrentTimeStep();
 		if (save) {
@@ -693,8 +693,8 @@ public class Control {
 
 	public void delObjUpperNode(AbstractCanvasObject object, GroupNode upperNode) {
 		nodeController.deleteObjectInUpperNode(object, upperNode);
-		if (object instanceof GroupNode)
-			canvasController.bfsNodeCleaner((GroupNode) object);
+		if (object instanceof GroupNode groupnode)
+			canvasController.bfsNodeCleaner(groupnode);
 		tryAutoSave();
 
 	}

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

@@ -287,8 +287,8 @@ public class LoadController {
     	}
         temp.initForReflection();
         temp.setImage(checkOS(temp.getImage()));
-        if (temp instanceof GroupNode) {
-            model.getHashcodeMap().put(jsonObject.get("hash").getAsInt(), (GroupNode) temp);
+        if (temp instanceof GroupNode groupnode) {
+            model.getHashcodeMap().put(jsonObject.get("hash").getAsInt(), groupnode);
         }
         // if its stored before on the canvas just put it there
         if (temp.getSav().equals("CVS")) {

+ 2 - 2
src/ui/controller/ObjectController.java

@@ -162,8 +162,8 @@ public class ObjectController {
 		for (AbstractCanvasObject obj : list) {
 			if (obj instanceof HolonObject) {
 				val++;
-			} else if (obj instanceof GroupNode) {
-				val += getNumberHolonObjects(((GroupNode) obj).getNodes());
+			} else if (obj instanceof GroupNode groupnode) {
+				val += getNumberHolonObjects(groupnode.getNodes());
 			}
 		}
 		return val;

+ 4 - 4
src/ui/controller/SaveController.java

@@ -224,12 +224,12 @@ public class SaveController {
             if (u instanceof HolonObject)
                 elementsToJson(TYPE.CANVAS, file, u);
             // if switch graphpoints too
-            if (u instanceof HolonSwitch)
-                if (((HolonSwitch) u).getGraphPoints().size() != 0)
+            if (u instanceof HolonSwitch sw)
+                if (sw.getGraphPoints().size() != 0)
                     unitgraphToJson(GRAPHTYPE.SWITCH, file, u.getId(), ((HolonSwitch) u).getGraphPoints());
             // if uppernode put all nodes inside the uppernode into queue
-            if (u instanceof GroupNode) {
-                for (AbstractCanvasObject adjacent : ((GroupNode) u).getNodes()) {
+            if (u instanceof GroupNode groupnode) {
+                for (AbstractCanvasObject adjacent : groupnode.getNodes()) {
                     queue.add(adjacent);
                 }
 

+ 3 - 3
src/ui/controller/SimulationManager.java

@@ -137,14 +137,14 @@ public class SimulationManager {
 			populateListOfNeighbors(edgeList, lookAtObject, actualNetwork, neighbors);
 			while(!neighbors.isEmpty()) {
 				AbstractCanvasObject lookAtNeighbor = neighbors.getFirst();
-				if(lookAtNeighbor instanceof HolonObject) {
-					actualNetwork.getHolonObjectList().add((HolonObject) lookAtNeighbor);
+				if(lookAtNeighbor instanceof HolonObject hO) {
+					actualNetwork.getHolonObjectList().add(hO);
 					holonObjectList.remove(lookAtNeighbor);
 				}else {
 					actualNetwork.getNodeAndSwitches().add(lookAtNeighbor);
 				}
 				//When HolonSwitch Check if closed
-				if(!(lookAtNeighbor instanceof HolonSwitch) || ((HolonSwitch)lookAtNeighbor).getState(Iteration)) {
+				if(!(lookAtNeighbor instanceof HolonSwitch sw) || sw.getState(Iteration)) {
 					populateListOfNeighbors(edgeList, lookAtNeighbor, actualNetwork, neighbors);
 				}
 				

+ 12 - 14
src/ui/model/MinimumModel.java

@@ -40,15 +40,14 @@ public class MinimumModel {
 
 	public MinimumModel(ArrayList<AbstractCanvasObject> abstractObjectList, ArrayList<Edge> edgeList, int timestep) {// Constructor because of old Model
 		for (AbstractCanvasObject aCps : abstractObjectList) {
-			if (aCps instanceof HolonObject) {
-				HolonObject hObject = (HolonObject) aCps;
+			if (aCps instanceof HolonObject hObject) {
 				holonObjectList.add(hObject);
 			}
-			else if (aCps instanceof Node) nodeList.add((Node) aCps);
-			else if (aCps instanceof HolonSwitch) switchList.add((HolonSwitch) aCps);
-			else if(aCps instanceof GroupNode) {
-				addGroupNodeObjects((GroupNode)aCps, timestep);
-				uppderNodeList.add((GroupNode)aCps);
+			else if (aCps instanceof Node node) nodeList.add(node);
+			else if (aCps instanceof HolonSwitch sw) switchList.add(sw);
+			else if(aCps instanceof GroupNode groupnode) {
+				addGroupNodeObjects(groupnode, timestep);
+				uppderNodeList.add(groupnode);
 			}
 		}
 		for (Edge edge : edgeList) {
@@ -72,15 +71,14 @@ public class MinimumModel {
 
 	private void addGroupNodeObjects(GroupNode aUpperNode, int timestep) {
 		for(AbstractCanvasObject aCps : aUpperNode.getNodes()) {
-			if (aCps instanceof HolonObject) {
-				HolonObject hObject = (HolonObject) aCps;
+			if (aCps instanceof HolonObject hObject) {
 				holonObjectList.add(hObject);
 			}
-			else if (aCps instanceof Node) nodeList.add((Node) aCps);
-			else if (aCps instanceof HolonSwitch) switchList.add((HolonSwitch) aCps);
-			else if(aCps instanceof GroupNode) {
-				addGroupNodeObjects((GroupNode)aCps, timestep);
-				uppderNodeList.add((GroupNode)aCps);
+			else if (aCps instanceof Node node) nodeList.add(node);
+			else if (aCps instanceof HolonSwitch sw) switchList.add(sw);
+			else if(aCps instanceof GroupNode groupnode) {
+				addGroupNodeObjects(groupnode, timestep);
+				uppderNodeList.add(groupnode);
 			}
 			inGroupObjects.put(aCps, aUpperNode);
 		}

+ 14 - 14
src/ui/model/Model.java

@@ -485,10 +485,10 @@ public class Model {
     
     private void getAllHolonObjectsRecursive(ArrayList<HolonObject> addObjectsToThisList, List<AbstractCanvasObject> listOfObjectsToSearch){
     	for(AbstractCanvasObject aCps : listOfObjectsToSearch) {
-    		if(aCps instanceof HolonObject) {
-    			addObjectsToThisList.add((HolonObject) aCps);
-    		}else if(aCps instanceof GroupNode){
-    			getAllHolonObjectsRecursive(addObjectsToThisList, ((GroupNode)aCps).getNodes());
+    		if(aCps instanceof HolonObject hO) {
+    			addObjectsToThisList.add(hO);
+    		}else if(aCps instanceof GroupNode groupnode){
+    			getAllHolonObjectsRecursive(addObjectsToThisList, groupnode.getNodes());
     		}
     	}
     }
@@ -500,8 +500,8 @@ public class Model {
     }
     private void getAllAsbtractObjectsRecursive(ArrayList<AbstractCanvasObject> addObjectsToThisList, List<AbstractCanvasObject> listOfObjectsToSearch){
     	for(AbstractCanvasObject aCps : listOfObjectsToSearch) {
-    		if(aCps instanceof GroupNode){
-    			getAllAsbtractObjectsRecursive(addObjectsToThisList, ((GroupNode)aCps).getNodes());
+    		if(aCps instanceof GroupNode groupnode){
+    			getAllAsbtractObjectsRecursive(addObjectsToThisList, groupnode.getNodes());
     		}
     		else{
     			addObjectsToThisList.add(aCps);
@@ -517,10 +517,10 @@ public class Model {
     public ArrayList<HolonSwitch> getAllSwitches() {
         ArrayList<HolonSwitch> switches = new ArrayList<>();
         for (AbstractCanvasObject obj : getObjectsOnCanvas()) {
-            if (obj instanceof HolonSwitch) {
-                switches.add((HolonSwitch) obj);
-            } else if (obj instanceof GroupNode) {
-                getSwitchesRec(((GroupNode) obj).getNodes(), switches);
+            if (obj instanceof HolonSwitch sw) {
+                switches.add(sw);
+            } else if (obj instanceof GroupNode groupnode) {
+                getSwitchesRec(groupnode.getNodes(), switches);
             }
         }
         return switches;
@@ -535,10 +535,10 @@ public class Model {
     private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCanvasObject> objects,
                                                   ArrayList<HolonSwitch> switches) {
         for (AbstractCanvasObject obj : objects) {
-            if (obj instanceof HolonSwitch) {
-                switches.add((HolonSwitch) obj);
-            } else if (obj instanceof GroupNode) {
-                getSwitchesRec(((GroupNode) obj).getNodes(), switches);
+            if (obj instanceof HolonSwitch sw) {
+                switches.add(sw);
+            } else if (obj instanceof GroupNode groupnode) {
+                getSwitchesRec(groupnode.getNodes(), switches);
             }
         }
         return switches;

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

@@ -693,12 +693,12 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 			markObjects();
 
 			boolean doubleclick = doubleClick();
-			if (doubleclick && tempCps instanceof HolonSwitch && MouseEvent.BUTTON3 != e.getButton()
+			if (doubleclick && tempCps instanceof HolonSwitch sw && MouseEvent.BUTTON3 != e.getButton()
 					&& tempCps != null) {
-				((HolonSwitch) tempCps).switchState();
+				sw.switchState();
 			}
-			if (doubleclick && tempCps != null && tempCps instanceof GroupNode) {
-				controller.getGui().openNewUpperNodeTab((GroupNode) tempCps);
+			if (doubleclick && tempCps != null && tempCps instanceof GroupNode groupnode) {
+				controller.getGui().openNewUpperNodeTab(groupnode);
 			}
 			controller.calculateStateAndVisualForTimeStep(model.getActualTimeStep());
 
@@ -865,8 +865,8 @@ public class Canvas extends AbstractCanvas implements MouseListener, MouseMotion
 						if (!(cps instanceof GroupNode || tempCps instanceof GroupNode)) {
 							e = new Edge(cps, tempCps, model.getMaxCapacity());
 							controller.addEdgeOnCanvas(e);
-						} else if (cps instanceof GroupNode && !(tempCps instanceof GroupNode)) {
-							GroupNode thisUpperNode = (GroupNode) cps;
+						} else if (cps instanceof GroupNode groupnode && !(tempCps instanceof GroupNode)) {
+							GroupNode thisUpperNode = groupnode;
 							Object[] possibilities = thisUpperNode.getNodes().stream().map(aCps -> new ACpsHandle(aCps))
 									.filter(aCpsHandle -> !(aCpsHandle.object instanceof GroupNode)).toArray();
 							if (possibilities.length != 0) {

+ 4 - 4
src/ui/view/canvas/GroupNodeCanvas.java

@@ -300,11 +300,11 @@ public class GroupNodeCanvas extends Canvas {
 
 			markObjects();
 			boolean doubleclick = doubleClick();
-			if (doubleclick && tempCps != null && tempCps instanceof HolonSwitch) {
-				((HolonSwitch) tempCps).switchState();
+			if (doubleclick && tempCps != null && tempCps instanceof HolonSwitch sw) {
+				sw.switchState();
 			}
-			if (doubleclick && tempCps != null && tempCps instanceof GroupNode) {
-				controller.getGui().openNewUpperNodeTab((GroupNode) tempCps);
+			if (doubleclick && tempCps != null && tempCps instanceof GroupNode groupnode) {
+				controller.getGui().openNewUpperNodeTab(groupnode);
 			}
 			controller.calculateStateAndVisualForTimeStep(model.getActualTimeStep());
 			repaint();

+ 2 - 4
src/ui/view/component/ButtonTabComponent.java

@@ -125,16 +125,14 @@ public class ButtonTabComponent extends JPanel {
 	private final static MouseListener buttonMouseListener = new MouseAdapter() {
 		public void mouseEntered(MouseEvent e) {
 			Component component = e.getComponent();
-			if (component instanceof AbstractButton) {
-				AbstractButton button = (AbstractButton) component;
+			if (component instanceof AbstractButton button) {
 				button.setBorderPainted(true);
 			}
 		}
 
 		public void mouseExited(MouseEvent e) {
 			Component component = e.getComponent();
-			if (component instanceof AbstractButton) {
-				AbstractButton button = (AbstractButton) component;
+			if (component instanceof AbstractButton button) {
 				button.setBorderPainted(false);
 			}
 		}

+ 55 - 60
src/ui/view/main/GUI.java

@@ -374,10 +374,9 @@ public class GUI {
 				JScrollPane scrollPane = getScrollPaneFromTabbedPane();
 				Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
 
-				if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
-					GroupNodeCanvas uNC = (GroupNodeCanvas) canvasOrUpperNodeCanvas;
-					controller.addSelectedObjects(uNC.getGroupNode().getNodes());
-					uNC.repaint();
+				if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
+					controller.addSelectedObjects(groupNodeCanvas.getGroupNode().getNodes());
+					groupNodeCanvas.repaint();
 					// or Canvas?
 				} else if (canvasOrUpperNodeCanvas instanceof Canvas) {
 					controller.addSelectedObjects(model.getObjectsOnCanvas());
@@ -406,27 +405,26 @@ public class GUI {
 				// complete re-evaluation of the net)
 				boolean wasProducerDeleted = true;
 
-				if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
-					GroupNodeCanvas uNC = (GroupNodeCanvas) canvasOrUpperNodeCanvas;
+				if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
 					for (AbstractCanvasObject cps : model.getSelectedObjects()) {
-						if (uNC.getGroupNode().getNodes().contains(cps)) {
-							controller.delObjUpperNode(cps, uNC.getGroupNode());
+						if (groupNodeCanvas.getGroupNode().getNodes().contains(cps)) {
+							controller.delObjUpperNode(cps, groupNodeCanvas.getGroupNode());
 							unc.setToolTip(false);
 
 							// remove UpperNodeTab if UpperNode deleted
 							removeUpperNodeTab(cps);
 						}
 					}
-					uNC.repaint();
+					groupNodeCanvas.repaint();
 					controller.clearSelection();
 
 					// or Canvas?
-				} else if (canvasOrUpperNodeCanvas instanceof Canvas) {
+				} else if (canvasOrUpperNodeCanvas instanceof Canvas canvasPanel) {
 					// Edge Deleting
 					Edge edgeHighlight = model.getSelectedEdge();
 					if (edgeHighlight != null) {
 						controller.removeEdgesOnCanvas(edgeHighlight);
-						((Canvas) canvasOrUpperNodeCanvas).edgeHighlight = null;
+						canvasPanel.edgeHighlight = null;
 					}
 					canvas.setToolTip(false);
 					for (AbstractCanvasObject cps : model.getSelectedObjects()) {
@@ -474,8 +472,8 @@ public class GUI {
 				System.out.println("heiCopy - control C");
 				JScrollPane scrollPane = getScrollPaneFromTabbedPane();
 				if (!model.getSelectedObjects().isEmpty()) {
-					if (scrollPane.getViewport().getComponent(0) instanceof GroupNodeCanvas)
-						controller.copy(((GroupNodeCanvas) scrollPane.getViewport().getComponent(0)).getGroupNode());
+					if (scrollPane.getViewport().getComponent(0) instanceof GroupNodeCanvas groupNodeCanvas)
+						controller.copy(groupNodeCanvas.getGroupNode());
 					else
 						controller.copy(null);
 					if (!model.getClipboradObjects().isEmpty()) {
@@ -505,9 +503,9 @@ public class GUI {
 					JScrollPane scrollPane = getScrollPaneFromTabbedPane();
 					Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
 
-					if (tabTemp != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
+					if (tabTemp != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
 
-						controller.paste(((GroupNodeCanvas) canvasOrUpperNodeCanvas).getGroupNode(),
+						controller.paste(groupNodeCanvas.getGroupNode(),
 								canvasOrUpperNodeCanvas.getMousePosition());
 						controller.calculateStateAndVisualForCurrentTimeStep();
 						scrollPane.getViewport().getComponent(0).repaint();
@@ -535,8 +533,8 @@ public class GUI {
 				chooseTabTemp();
 				JScrollPane scrollPane = getScrollPaneFromTabbedPane();
 				if (!model.getSelectedObjects().isEmpty()) {
-					if (scrollPane.getViewport().getComponent(0) instanceof GroupNodeCanvas) {
-						controller.cut(((GroupNodeCanvas) scrollPane.getViewport().getComponent(0)).getGroupNode());
+					if (scrollPane.getViewport().getComponent(0) instanceof GroupNodeCanvas groupNodeCanvas) {
+						controller.cut(groupNodeCanvas.getGroupNode());
 						controller.calculateStateAndVisualForCurrentTimeStep();
 						scrollPane.getViewport().getComponent(0).repaint();
 					} else {
@@ -639,8 +637,8 @@ public class GUI {
 			controller.calculateStateAndVisualForCurrentTimeStep();
 			// Update UpperNodes
 			Component canvasOrUpperNodeCanvas = getScrollPaneFromTabbedPane().getViewport().getComponent(0);
-			if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
-				((GroupNodeCanvas) canvasOrUpperNodeCanvas).repaint();
+			if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
+				groupNodeCanvas.repaint();
 			}
 		});
 
@@ -654,8 +652,8 @@ public class GUI {
 			controller.calculateStateAndVisualForCurrentTimeStep();
 			// Update UpperNodes
 			Component canvasOrUpperNodeCanvas = getScrollPaneFromTabbedPane().getViewport().getComponent(0);
-			if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
-				((GroupNodeCanvas) canvasOrUpperNodeCanvas).repaint();
+			if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
+				groupNodeCanvas.repaint();
 			}
 		});
 
@@ -687,8 +685,8 @@ public class GUI {
 			JScrollPane spane = getScrollPaneFromTabbedPane();
 			if (spane != null) {
 				Component canvasOrUpperNodeCanvas = spane.getViewport().getComponent(0);
-				if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
-					((GroupNodeCanvas) canvasOrUpperNodeCanvas).repaint();
+				if (canvasOrUpperNodeCanvas != null && canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
+					groupNodeCanvas.repaint();
 				}
 			}
 		});
@@ -704,13 +702,12 @@ public class GUI {
 				BackgroundPopUp backgroundDialog = new BackgroundPopUp(model, controller, canvas, null, holegJFrame);
 				backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
 				backgroundDialog.setVisible(true);
-			} else if (scrollPane.getViewport().getComponent(0) instanceof GroupNodeCanvas) {
-				GroupNodeCanvas uNodeCanvas = (GroupNodeCanvas) (scrollPane.getViewport().getComponent(0));
+			} else if (scrollPane.getViewport().getComponent(0) instanceof GroupNodeCanvas groupNodeCanvas) {
 				BackgroundPopUp backgroundDialog = new BackgroundPopUp(model, controller, null,
-						uNodeCanvas.getGroupNode(), holegJFrame);
+						groupNodeCanvas.getGroupNode(), holegJFrame);
 				backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
 				backgroundDialog.setVisible(true);
-				uNodeCanvas.repaint();
+				groupNodeCanvas.repaint();
 			}
 		});
 
@@ -850,8 +847,7 @@ public class GUI {
 					/**
 					 * check for replacements on the canvas
 					 */
-					if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
-						GroupNodeCanvas unc = (GroupNodeCanvas) canvasOrUpperNodeCanvas;
+					if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
 						if (unc.getMousePosition() == null)
 							return;
 						int x = (int) unc.getMousePosition().getX() + 16;
@@ -860,7 +856,7 @@ public class GUI {
 						/**
 						 * check for replacement
 						 */
-						unc.checkForReplacement(x, y);
+						groupNodeCanvas.checkForReplacement(x, y);
 
 						/**
 						 * repaint
@@ -901,46 +897,45 @@ public class GUI {
 						JScrollPane scrollPane = getScrollPaneFromTabbedPane();
 						Component canvasOrUpperNodeCanvas = scrollPane.getViewport().getComponent(0);
 
-						if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas) {
-							GroupNodeCanvas unc = (GroupNodeCanvas) canvasOrUpperNodeCanvas;
-							int x = (int) unc.getMousePosition().getX() + 16;
-							int y = (int) unc.getMousePosition().getY() + 16;
+						if (canvasOrUpperNodeCanvas instanceof GroupNodeCanvas groupNodeCanvas) {
+							int x = (int) groupNodeCanvas.getMousePosition().getX() + 16;
+							int y = (int) groupNodeCanvas.getMousePosition().getY() + 16;
 
 							AbstractCanvasObject h = null;
-							if (tempCps instanceof HolonObject) {
-								h = new HolonObject((HolonObject) tempCps);
+							if (tempCps instanceof HolonObject hO) {
+								h = new HolonObject(hO);
 							}
-							if (tempCps instanceof HolonSwitch) {
-								h = new HolonSwitch(tempCps);
+							if (tempCps instanceof HolonSwitch sw) {
+								h = new HolonSwitch(sw);
 							}
 							h.setPosition(x, y);
 
 							/**
 							 * close UpperNodeTabs of replaced UpperNode
 							 */
-							if (unc.mayBeReplaced != null && unc.mayBeReplaced instanceof GroupNode) {
-								unc.closeUpperNodeTab(unc.mayBeReplaced.getId());
+							if (groupNodeCanvas.mayBeReplaced != null && groupNodeCanvas.mayBeReplaced instanceof GroupNode) {
+								groupNodeCanvas.closeUpperNodeTab(groupNodeCanvas.mayBeReplaced.getId());
 							}
-							controller.addObjUpperNode(h, unc.getGroupNode());
+							controller.addObjUpperNode(h, groupNodeCanvas.getGroupNode());
 
 							/**
 							 * object would be replaced
 							 */
-							unc.mayBeReplaced = null;
-							unc.invalidate();
+							groupNodeCanvas.mayBeReplaced = null;
+							groupNodeCanvas.invalidate();
 							controller.calculateStateAndVisualForCurrentTimeStep();
-							unc.repaint();
-							unc.setXY((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
+							groupNodeCanvas.repaint();
+							groupNodeCanvas.setXY((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
 						} else {
 							int x = (int) canvas.getMousePosition().getX() + 16;
 							int y = (int) canvas.getMousePosition().getY() + 16;
 
 							AbstractCanvasObject h = null;
-							if (tempCps instanceof HolonObject) {
-								h = new HolonObject((HolonObject) tempCps);
+							if (tempCps instanceof HolonObject hO) {
+								h = new HolonObject(hO);
 							}
-							if (tempCps instanceof HolonSwitch) {
-								h = new HolonSwitch(tempCps);
+							if (tempCps instanceof HolonSwitch sw) {
+								h = new HolonSwitch(sw);
 							}
 
 							h.setPosition(x, y);
@@ -1531,13 +1526,13 @@ public class GUI {
 		chooseTabTemp();
 
 		JScrollPane scrollPane = getScrollPaneFromTabbedPane();
-		if (scrollPane.getViewport().getComponent(0) instanceof Canvas) {
+		if (scrollPane.getViewport().getComponent(0) instanceof Canvas canvasPanel) {
 			unc = new GroupNodeCanvas(model, controller, unitGraph, node, "",
-					scrollPane.getViewport().getComponent(0));
+					canvasPanel);
 
-		} else {
+		} else if(scrollPane.getViewport().getComponent(0) instanceof GroupNodeCanvas groupNodeCanvas) {
 			unc = new GroupNodeCanvas(model, controller, unitGraph, node,
-					((GroupNodeCanvas) scrollPane.getViewport().getComponent(0)).getParentPath() + " -> ",
+					groupNodeCanvas.getParentPath() + " -> ",
 					scrollPane.getViewport().getComponent(0));
 		}
 
@@ -1582,9 +1577,9 @@ public class GUI {
 				continue;
 			}
 			Component pane = ((JScrollPane) c).getViewport().getComponent(0);
-			if (pane instanceof GroupNodeCanvas) {
-				temp = model.getHashcodeMap().get(((GroupNodeCanvas) pane).hashCode());
-				((GroupNodeCanvas) pane).setGroupNode((GroupNode) temp);
+			if (pane instanceof GroupNodeCanvas groupNodeCanvas) {
+				temp = model.getHashcodeMap().get(groupNodeCanvas.hashCode());
+				groupNodeCanvas.setGroupNode((GroupNode) temp);
 			}
 		}
 	}
@@ -1633,13 +1628,13 @@ public class GUI {
 		}
 		if (upperLevelSelectedComponent instanceof JTabbedPane) {
 			Component nextLevel = ((JTabbedPane) upperLevelSelectedComponent).getSelectedComponent();
-			if (nextLevel instanceof JPanel)
-				return (JScrollPane) ((JPanel) nextLevel).getComponent(0);
+			if (nextLevel instanceof JPanel panel)
+				return (JScrollPane) panel.getComponent(0);
 			else
 				return (JScrollPane) nextLevel;
 
-		} else if (upperLevelSelectedComponent instanceof JScrollPane) {
-			return (JScrollPane) upperLevelSelectedComponent;
+		} else if (upperLevelSelectedComponent instanceof JScrollPane scrollPane) {
+			return scrollPane;
 		} else {
 			return null;
 		}

+ 0 - 1
src/ui/view/main/TimePanel.java

@@ -47,7 +47,6 @@ import utility.listener.LostFocusListener;
  */
 public class TimePanel extends JPanel implements ActionListener {
 
-	private static final long serialVersionUID = 1L;
 	private static final int MAX_ITERATIONS = 100000;
 	/*
 	 * variable for calculating the performance

+ 4 - 4
src/ui/view/window/AddOnWindow.java

@@ -153,13 +153,13 @@ public class AddOnWindow extends JFrame{
 		URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { folder.toURI().toURL() });
 		Class<?> cls = Class.forName(packageName.isEmpty()?name:packageName + "." +name, true, classLoader);
 		Object object = cls.getDeclaredConstructor().newInstance();
-		if(!(object instanceof AddOn)) {
-			generateErrorDialog("Class does not implement CpsAlgorithm!");
-		}else {
-			actual = (AddOn)object;
+		if(object instanceof AddOn addon) {
+			actual = addon;
 			actual.setController(control);
 			this.setContentPane(actual.getPanel());
 			this.pack();
+		}else {
+			generateErrorDialog("Class does not implement CpsAlgorithm!");
 		}
 		} catch (MalformedURLException e) {
 			generateErrorDialog("URLClassLoader error");

+ 12 - 11
src/ui/view/window/FlexWindow.java

@@ -319,7 +319,7 @@ public class FlexWindow extends JFrame {
 									for (TreePath path : stateTree.getSelectionPaths()) {
 										Object treeNodeUserObject = ((DefaultMutableTreeNode) path.getLastPathComponent())
 												.getUserObject();
-										if (treeNodeUserObject instanceof ElementInfo) {
+										if (treeNodeUserObject instanceof ElementInfo eleInfo) {
 											if (prio == null)
 												prio = (Priority) JOptionPane.showInputDialog(stateTree,
 														"Select the Priority:", "Priority?", JOptionPane.OK_OPTION,
@@ -327,7 +327,6 @@ public class FlexWindow extends JFrame {
 														Priority.values(), "");
 											if (prio == null)
 												break;
-											ElementInfo eleInfo = (ElementInfo) treeNodeUserObject;
 											eleInfo.ele.setPriority(prio);
 											treeModel.reload((DefaultMutableTreeNode) path.getLastPathComponent());
 										}
@@ -339,9 +338,11 @@ public class FlexWindow extends JFrame {
 									return;
 								Object treeNodeUserObject = ((DefaultMutableTreeNode) path.getLastPathComponent())
 										.getUserObject();
-								if (!(treeNodeUserObject instanceof ElementInfo))
-									return;
-								createAddDialog(((ElementInfo) treeNodeUserObject).ele);
+								if (treeNodeUserObject instanceof ElementInfo eleInfo) {
+									createAddDialog(eleInfo.ele);									
+								}else {
+									return;									
+								}
 			   	        });
 			         	    
 		                    menu.add ( priorityItem );
@@ -379,8 +380,8 @@ public class FlexWindow extends JFrame {
 		//Init with HolonObjects
 		for(AbstractCanvasObject aCps: model.getObjectsOnCanvas()) {
 			DefaultMutableTreeNode newObjectChild = new DefaultMutableTreeNode(aCps.getName() + " ID:" + aCps.getId());
-			if(aCps instanceof HolonObject) expandTreeHolonObject((HolonObject)aCps, newObjectChild);
-			if(aCps instanceof GroupNode)expandTreeUpperNode((GroupNode)aCps, newObjectChild);
+			if(aCps instanceof HolonObject hO) expandTreeHolonObject(hO, newObjectChild);
+			if(aCps instanceof GroupNode groupnode)expandTreeUpperNode(groupnode, newObjectChild);
 			listOfAllSelectedHolonObjects.add(newObjectChild);
 		}
 		treeModel.nodeStructureChanged(listOfAllSelectedHolonObjects);
@@ -407,8 +408,8 @@ public class FlexWindow extends JFrame {
 	private void expandTreeUpperNode(GroupNode groupNode, DefaultMutableTreeNode root) {
 		for(AbstractCanvasObject aCps: groupNode.getNodes()) {
 			DefaultMutableTreeNode newObjectChild = new DefaultMutableTreeNode(aCps.getName() + " ID:" + aCps.getId());
-			if(aCps instanceof HolonObject) expandTreeHolonObject((HolonObject)aCps, newObjectChild);
-			if(aCps instanceof GroupNode)expandTreeUpperNode((GroupNode)aCps, newObjectChild);
+			if(aCps instanceof HolonObject hO) expandTreeHolonObject(hO, newObjectChild);
+			if(aCps instanceof GroupNode groupnode)expandTreeUpperNode(groupnode, newObjectChild);
 			root.add(newObjectChild);
 		}
 		
@@ -463,8 +464,8 @@ public class FlexWindow extends JFrame {
 	private List<HolonObject> createListOfHolonObjects(List<AbstractCanvasObject> objectsOnCanvas) {
 		List<HolonObject> list = new ArrayList<HolonObject>();
 		for(AbstractCanvasObject aCps :  objectsOnCanvas) {
-			if(aCps instanceof HolonObject) list.add((HolonObject) aCps);
-			else if (aCps instanceof GroupNode) list.addAll(createListOfHolonObjects(((GroupNode)aCps).getNodes()));
+			if(aCps instanceof HolonObject hO) list.add(hO);
+			else if (aCps instanceof GroupNode groupnode) list.addAll(createListOfHolonObjects(groupnode.getNodes()));
 		}
 		return list;
 	}