|
@@ -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();
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
|
|
|
|