Bladeren bron

Start of little changes

Tom Troppmann 6 jaren geleden
bovenliggende
commit
8ddd4afe6c

+ 9 - 1
src/classes/HolonElement.java

@@ -2,7 +2,6 @@ package classes;
 
 import com.google.gson.annotations.Expose;
 
-import ui.controller.SingletonControl;
 import ui.model.Model;
 import ui.view.UnitGraph;
 
@@ -232,6 +231,15 @@ public class HolonElement implements IGraphedElement{
     public float getEnergyPerElement() {
         return energyPerElement;
     }
+    
+    /**
+     *  Return if the HolonElemnt is a Producer
+     * 	@return boolean true when the energy used be each element is higher then 0
+     */
+    public boolean isProducer()
+    {
+    	return (energyPerElement > 0);
+    }
 
     /**
      * Set the energyPerElement value of the selected Element.

+ 16 - 4
src/classes/HolonObject.java

@@ -88,11 +88,11 @@ public class HolonObject extends AbstractCpsObject {
      * partially or over-supplied
      */
     public void setState() {
-        if (getCurrentEnergy() > 0) {
+        if (getMaxActiveEnergy() > 0) {
             setState(PRODUCER);
             stateColor = Color.lightGray;
         } else {
-            if (getCurrentEnergy() == 0) {
+            if (getMaxActiveEnergy() == 0) {
                 setState(NO_ENERGY);
                 stateColor = Color.WHITE;
             } else {
@@ -139,7 +139,7 @@ public class HolonObject extends AbstractCpsObject {
      *
      * @return the currentEnergy
      */
-    public float getCurrentEnergy() {
+    public float getMaxActiveEnergy() {
         float temp = 0;
         for (HolonElement e : getElements()) {
             if (e.isActive()) {
@@ -147,9 +147,21 @@ public class HolonObject extends AbstractCpsObject {
             }
         }
         currentEnergy = temp;
-        return currentEnergy;
+        return temp;
     }
+    
+    
 
+	public HolonElement getMinimalConsumingElement() {
+		HolonElement min = elements.get(0);
+		for (HolonElement e : elements) {
+			if (e.getOverallEnergy() < 0 && e.getOverallEnergy() > min.getOverallEnergy()) {
+				min = e;
+			}
+		}
+		return min;
+	}
+    
     /**
      * Getter for the current energy at a given timestep.
      *

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

@@ -48,7 +48,7 @@ public class UpdateController {
 			if (tempCps != null && tempCps.getClass() == HolonObject.class) {
 				if (table.getRowCount() != 0) {
 					table.removeRow(2);
-					Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) tempCps).getCurrentEnergy() };
+					Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) tempCps).getMaxActiveEnergy() };
 					table.insertRow(2, tempEnergy);
 					((HolonObject) tempCps).updateTotalFlex();
 					table.removeRow(3);
@@ -297,7 +297,7 @@ public class UpdateController {
 			// consumption) is calculated
 			if (obj instanceof HolonObject) {
 				refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
-				Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) obj).getCurrentEnergy() };
+				Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) obj).getMaxActiveEnergy() };
 				Object[] tempFlex = { "Flexibility", ((HolonObject) obj).getTotalFlex() };
 				model.getPropertyTable().addRow(tempEnergy);
 				model.getPropertyTable().addRow(tempFlex);

+ 3 - 3
tests/tests/PraktikumHolonsTestClasses.java

@@ -60,16 +60,16 @@ public class PraktikumHolonsTestClasses {
 		arr.add(ele);
 		arr.add(ele);
 		assertTrue("Should be Empty", test2.getElements().isEmpty());
-		assertTrue("Current Energy not corrent", test2.getCurrentEnergy() == 0);
+		assertTrue("Current Energy not corrent", test2.getMaxActiveEnergy() == 0);
 		test2.setElements(arr);
 		assertTrue("Should not be Empty", !test2.getElements().isEmpty());
-		assertTrue("Current Energy not corrent", test2.getCurrentEnergy() == 20);
+		assertTrue("Current Energy not corrent", test2.getMaxActiveEnergy() == 20);
 		assertTrue("Current Energy not corrent", test2.getCurrentEnergyAtTimeStep(20) == 20);
 		String str = test2.toStringElements();
 		assertTrue("String not corrent", str.equals("Element, Element"));
 		test2.deleteElement(0);
 		test2.addElement(ele);
-		assertTrue("Current Energy not corrent", test2.getCurrentEnergy() == 20);
+		assertTrue("Current Energy not corrent", test2.getMaxActiveEnergy() == 20);
 		assertTrue("Should be Empty", test3.getElements().isEmpty());
 		test3.setElements(test2.copyElements(test2.getElements()));
 		assertTrue("Should be Empty", !test3.getElements().isEmpty());

+ 1 - 1
tests/tests/PraktikumHolonsTestObjectController.java

@@ -70,7 +70,7 @@ public class PraktikumHolonsTestObjectController {
 			controller.addNewElementIntoCategoryObject("Building", "House", adapter.generate(i), i, -10);
 			// n(n+1) / 2
 			assertTrue("Total Energy does not match", ((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"))
-					.getCurrentEnergy() == -1800 + ((i * (i + 1)) / 2) * -10);
+					.getMaxActiveEnergy() == -1800 + ((i * (i + 1)) / 2) * -10);
 			assertTrue("Number of Elements does not Match",
 					((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House")).getElements().size() == 6 + i);
 		}