Browse Source

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

Jessey Widhalm 7 years ago
parent
commit
9f0e6c217e
3 changed files with 113 additions and 43 deletions
  1. 103 41
      src/classes/HolonObject.java
  2. 8 0
      src/classes/HolonSwitch.java
  3. 2 2
      src/ui/controller/SimulationManager.java

+ 103 - 41
src/classes/HolonObject.java

@@ -7,8 +7,19 @@ import java.util.HashMap;
 import ui.controller.MultiPurposeController;
 import ui.model.idCounter;
 
+/**
+ * The class HolonObject represents any Object on the system which capability of
+ * injecting or consuming energy on the network, for instance a house or a power
+ * plant.
+ * 
+ * @author Gruppe14
+ *
+ */
 public class HolonObject extends CpsObject {
-	
+	/*
+	 * Color of the actual state (red = no supplied, yellow = partially supplied
+	 * and green = supplied)
+	 */
 	private Color stateColor;
 	/* Array of all consumers */
 	private ArrayList<HolonElement> elements;
@@ -17,10 +28,10 @@ public class HolonObject extends CpsObject {
 	/* Total of consumption */
 	private float currentEnergy;
 
-	/**
+	/*
 	 * 0 = no energy, 1 = not supplied, 2 = supplied, 3 producer
 	 */
-	int state = 0;
+	private int state = 0;
 
 	/**
 	 * Constructor Set by default the name of the object equals to the category
@@ -33,6 +44,14 @@ public class HolonObject extends CpsObject {
 		setState();
 	}
 
+	/**
+	 * Constructor with a user-defined name
+	 * 
+	 * @param ObjName
+	 *            Type of Object
+	 * @param obj
+	 *            user-defined name
+	 */
 	public HolonObject(String ObjName, String obj) {
 		super(ObjName);
 		super.setName(obj);
@@ -41,6 +60,12 @@ public class HolonObject extends CpsObject {
 		setState();
 	}
 
+	/**
+	 * Contructor of a copy of an Object
+	 * 
+	 * @param obj
+	 *            object to be copied
+	 */
 	public HolonObject(CpsObject obj) {
 		super(obj);
 		setEleIdx(MultiPurposeController.copyHashMap(((HolonObject) obj).getEleIdx()));
@@ -60,25 +85,29 @@ public class HolonObject extends CpsObject {
 			if (getCurrentEnergy() == 0) {
 				setState(0);
 				stateColor = Color.WHITE;
-			}else {
-				if(checkIfPartiallySupplied(0)){
+			} else {
+				if (checkIfPartiallySupplied(0)) {
 					stateColor = Color.yellow;
-				}else {
-					stateColor = new Color(230,120,100);
+				} else {
+					stateColor = new Color(230, 120, 100);
 				}
-				
+
 			}
 		}
 	}
 
 	/**
-	 * @return the elements
+	 * Getter for all Elements in the HolonObject
+	 * 
+	 * @return the elements ArrayList
 	 */
 	public ArrayList<HolonElement> getElements() {
 		return elements;
 	}
 
 	/**
+	 * Set a new ArrayList with HolonElements into the HolonObject
+	 * 
 	 * @param elements
 	 *            the elements to set
 	 */
@@ -91,8 +120,9 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
-	 * doesnt take into account which timestep is watched,
-	 * calculates the max values
+	 * Doesn't take into account which timestep is watched, calculates the max
+	 * values
+	 * 
 	 * @return the currentEnergy
 	 */
 	public float getCurrentEnergy() {
@@ -106,6 +136,13 @@ public class HolonObject extends CpsObject {
 		return currentEnergy;
 	}
 
+	/**
+	 * Getter for the current energy at a given timestep
+	 * 
+	 * @param x
+	 *            timestep
+	 * @return corresponding energy
+	 */
 	public float getCurrentEnergyAtTimeStep(int x) {
 		float temp = 0;
 		for (HolonElement e : getElements()) {
@@ -118,17 +155,10 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
-	 * @param currentEnergy
-	 *            the currentEnergy to set
-	 */
-	public void setCurrentEnergy(float currentEnergy) {
-		this.currentEnergy = currentEnergy;
-	}
-
-	/**
-	 * deletes Element
+	 * deletes Element at a given index
 	 * 
 	 * @param idx
+	 *            index
 	 */
 	public void deleteElement(int idx) {
 		elements.remove(idx);
@@ -152,6 +182,8 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
+	 * Getter index of all elements in the HolonObject
+	 * 
 	 * @return the eleIdx
 	 */
 	public HashMap<String, Integer> getEleIdx() {
@@ -159,6 +191,8 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
+	 * Set the indexes of all elements
+	 * 
 	 * @param eleIdx
 	 *            the eleIdx to set
 	 */
@@ -180,36 +214,52 @@ public class HolonObject extends CpsObject {
 		return newArr;
 	}
 
-	/*
-	 * returns supplied
+	/**
+	 * Get the state of the Object
+	 * 
+	 * @return state
 	 */
 	public int getState() {
 		return this.state;
 	}
 
 	/**
+	 * Set the state of the Object
+	 * 
 	 * @param supplied
 	 *            boolean if the Object is fully supplied
 	 */
 	public void setState(int st) {
 		this.state = st;
-		switch(st){
-			case 0: stateColor = Color.WHITE;
-					break;
-			
-			case 1: stateColor = new Color(230,120,100);
-					break;
-					
-			case 2: stateColor = Color.GREEN;
-					break;
-			
-			case 3: stateColor = Color.lightGray;
-					break;
-			
-			case 4: stateColor = Color.YELLOW;
+		switch (st) {
+		case 0:
+			stateColor = Color.WHITE;
+			break;
+
+		case 1:
+			stateColor = new Color(230, 120, 100);
+			break;
+
+		case 2:
+			stateColor = Color.GREEN;
+			break;
+
+		case 3:
+			stateColor = Color.lightGray;
+			break;
+
+		case 4:
+			stateColor = Color.YELLOW;
 		}
 	}
 
+	/**
+	 * Search for the element with the name
+	 * 
+	 * @param name
+	 *            name of the object to be searched
+	 * @return the searched HolonElement
+	 */
 	public HolonElement searchElement(String name) {
 		HolonElement ele = null;
 		for (HolonElement e : getElements()) {
@@ -220,6 +270,13 @@ public class HolonObject extends CpsObject {
 		return ele;
 	}
 
+	/**
+	 * Search for the element with the id
+	 * 
+	 * @param id
+	 *            id of the element to be founded
+	 * @return the element
+	 */
 	public HolonElement searchElementById(int id) {
 		HolonElement ele = null;
 		for (HolonElement e : getElements()) {
@@ -230,6 +287,11 @@ public class HolonObject extends CpsObject {
 		return ele;
 	}
 
+	/**
+	 * 
+	 * @param x
+	 * @return
+	 */
 	public boolean checkIfPartiallySupplied(int x) {
 		if (getElements().size() == 0) {
 			return false;
@@ -248,19 +310,19 @@ public class HolonObject extends CpsObject {
 				}
 			}
 		}
-//		System.out.println("minCons: " + minConsum + " prod: " + prod);
+		// System.out.println("minCons: " + minConsum + " prod: " + prod);
 		if (minConsum < 0 && prod >= -minConsum) {
 			return true;
 		} else {
 			return false;
 		}
 	}
-	
-	public void setColor(Color color){
+
+	public void setColor(Color color) {
 		stateColor = color;
 	}
-	
-	public Color getColor(){
+
+	public Color getColor() {
 		return stateColor;
 	}
 }

+ 8 - 0
src/classes/HolonSwitch.java

@@ -65,6 +65,14 @@ public class HolonSwitch extends CpsObject {
 			this.manualActive = !manualActive;
 		}
 	}
+	
+	public boolean getState(int timeStep){
+		if(manualMode){
+			return this.manualActive;
+		} else {
+			return getActiveAt()[timeStep];
+		}
+	}
 
 	public boolean getState() {
 		if (manualMode) {

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

@@ -306,9 +306,9 @@ public class SimulationManager {
 	
 	public boolean legitState(CpsObject neighbor, CpsObject current){
 		if(current instanceof HolonSwitch){
-			if(((HolonSwitch) current).getActiveAt()[timeStep]){
+			if(((HolonSwitch) current).getState(timeStep)){
 				if(neighbor instanceof HolonSwitch){
-					if(((HolonSwitch) neighbor).getActiveAt()[timeStep]){
+					if(((HolonSwitch) neighbor).getState(timeStep)){
 						return true;
 					}else{
 						return false;