Преглед изворни кода

Zusammenführung bei HolonObject von Producers and Consumers zu elements, Anpassung der ObjectControl

Teh-Hai Julian Zheng пре 8 година
родитељ
комит
d22f14fbac

BIN
bin/classes/HolonObject.class


BIN
bin/ui/controller/ObjectControl.class


+ 38 - 53
src/classes/HolonObject.java

@@ -5,9 +5,7 @@ import java.util.ArrayList;
 public class HolonObject extends CpsObject {
 
 	/* Array of all consumers */
-	private ArrayList<HolonElement> consumers;
-	/* Array of all producers */
-	private ArrayList<HolonElement> producers;
+	private ArrayList<HolonElement> elements;
 	/* Total of consumption */
 	private float currentEnergy;
 	/**
@@ -22,69 +20,75 @@ public class HolonObject extends CpsObject {
 	 */
 	public HolonObject(String ObjName) {
 		super(ObjName);
-		consumers = new ArrayList<HolonElement>();
-		producers = new ArrayList<HolonElement>();
+		elements = new ArrayList<HolonElement>();
 	}
 
 	public HolonObject(String ObjName, String obj) {
 		super(ObjName);
 		super.name = obj;
-		consumers = new ArrayList<HolonElement>();
-		producers = new ArrayList<HolonElement>();
+		elements = new ArrayList<HolonElement>();
 	}
 
 	public HolonObject(CpsObject obj) {
 		super(obj);
-		consumers = new ArrayList<HolonElement>();
-		producers = new ArrayList<HolonElement>();
-		this.consumers = ((HolonObject)obj).getConsumers();
-		this.producers = ((HolonObject)obj).getProducers();
-	}
+		elements = new ArrayList<HolonElement>();
+		this.elements = ((HolonObject)obj).getElements();
 
-	public void addConsumer(HolonElement consumer) {
-		consumers.add(consumer);
 	}
 
-	public void addProducer(HolonElement producer) {
-		producers.add(producer);
-	}
 
-	public void deleteConsumer(int idx) {
-		consumers.remove(idx);
+
+	
+	/**
+	 * @return the elements
+	 */
+	public ArrayList<HolonElement> getElements() {
+		return elements;
 	}
 
-	public void deleteProducer(int idx) {
-		producers.remove(idx);
+	/**
+	 * @param elements the elements to set
+	 */
+	public void setElements(ArrayList<HolonElement> elements) {
+		this.elements = elements;
 	}
 
-	public float calculateCurrentEnergy() {
+	/**
+	 * @return the currentEnergy
+	 */
+	public float getCurrentEnergy() {
 		return currentEnergy;
 	}
 
-	public ArrayList<HolonElement> getConsumers() {
-		return consumers;
+	/**
+	 * @param currentEnergy the currentEnergy to set
+	 */
+	public void setCurrentEnergy(float currentEnergy) {
+		this.currentEnergy = currentEnergy;
 	}
 
-	public void setConsumers(ArrayList<HolonElement> consumers) {
-		this.consumers = consumers;
+	/**
+	 * deletes Element
+	 * @param idx
+	 */
+	public void deleteElement(int idx) {
+		elements.remove(idx);
 	}
 
-	public ArrayList<HolonElement> getProducers() {
-		return producers;
+	public float calculateCurrentEnergy() {
+		return currentEnergy;
 	}
 
-	public void setProducers(ArrayList<HolonElement> producers) {
-		this.producers = producers;
-	}
+	
 
 	/**
 	 * String of all consumers in this HolonObject
 	 * 
 	 * @return all the names of this HolonObject separated by "," each object
 	 */
-	public String toStringConsumers() {
+	public String toStringElements() {
 		String objString = "";
-		for (HolonElement e : consumers) {
+		for (HolonElement e : elements) {
 			if (objString == "") {
 				objString = e.getEleName();
 			} else {
@@ -94,23 +98,4 @@ public class HolonObject extends CpsObject {
 		}
 		return objString;
 	}
-
-	/**
-	 * String of all producers in this HolonObject
-	 * 
-	 * @return all the names of this HolonObject separated by "," each object
-	 */
-	public String toStringProducers() {
-		String objString = "";
-		for (HolonElement e : producers) {
-			if (objString == "") {
-				objString = e.getEleName();
-			} else {
-				objString = objString + ", " + e.getEleName();
-			}
-
-		}
-		return objString;
-	}
-
-}
+}

+ 11 - 18
src/ui/controller/ObjectControl.java

@@ -22,7 +22,7 @@ public class ObjectControl {
 
 	public ObjectControl(Model model) {
 		this.M = model;
-		ID = IdCounter.nextId();
+		this.ID = IdCounter.nextId();
 	}
 
 	/**
@@ -50,12 +50,9 @@ public class ObjectControl {
 	/**
 	 * Adds Element into a Object
 	 */
-	public void addElement(HolonObject object, HolonElement element, Type type) {
+	public void addElement(HolonObject object, HolonElement element) {
+		object.getElements().add(element);
 
-		if (type.equals(Type.CONSUMER))
-			object.getConsumers().add(element);
-		else
-			object.getProducers().add(element);
 	}
 
 	/**
@@ -65,8 +62,8 @@ public class ObjectControl {
 	 * @param element
 	 * @param type
 	 */
-	public void addElementIntoCanvasObject(String object, HolonElement element, Type type) {
-		addElement(searchHolonObject(object, M.getObjectsOnCanvas()), element, type);
+	public void addElementIntoCanvasObject(String object, HolonElement element) {
+		addElement(searchHolonObject(object, M.getObjectsOnCanvas()), element);
 	}
 
 	/**
@@ -78,8 +75,8 @@ public class ObjectControl {
 	 * @param energy
 	 * @param type
 	 */
-	public void addNewElementIntoCanvasObject(String object, String eleName, int amount, float energy, Type type) {
-		addElementIntoCanvasObject(object, new HolonElement(eleName, energy, amount), type);
+	public void addNewElementIntoCanvasObject(String object, String eleName, int amount, float energy) {
+		addElementIntoCanvasObject(object, new HolonElement(eleName, energy, amount));
 	}
 
 	/**
@@ -89,7 +86,7 @@ public class ObjectControl {
 	 * @param element
 	 * @param type
 	 */
-	public void addElementIntoCategoryObject(String category, String object, HolonElement element, Type type) {
+	public void addElementIntoCategoryObject(String category, String object, HolonElement element) {
 		Category cat = null;
 
 		for (Category cats : M.getCategories()) {
@@ -98,8 +95,7 @@ public class ObjectControl {
 				break;
 			}
 		}
-
-		addElement(searchHolonObject(object, cat.getObjects()), element, type);
+		addElement(searchHolonObject(object, cat.getObjects()), element);
 	}
 
 	/**
@@ -113,11 +109,8 @@ public class ObjectControl {
 	 * @param type
 	 */
 	public void addNewElementIntoCategoryObject(String category, String object, String eleName, int amount,
-			float energy, Type type) {
-
-		addElementIntoCategoryObject(category, object, new HolonElement(eleName, energy, amount), type);
-
-
+			float energy) {
+		addElementIntoCategoryObject(category, object, new HolonElement(eleName, energy, amount));
 	}
 
 	/**