|
@@ -2,6 +2,8 @@ package classes;
|
|
|
|
|
|
import com.google.gson.annotations.Expose;
|
|
|
|
|
|
+import ui.model.Model;
|
|
|
+
|
|
|
import java.awt.*;
|
|
|
import java.util.LinkedList;
|
|
|
|
|
@@ -45,6 +47,10 @@ public class HolonElement {
|
|
|
/* ID */
|
|
|
@Expose
|
|
|
private int id;
|
|
|
+
|
|
|
+ private static final int DEFAULT_GRAPH_LENGTH=100;
|
|
|
+ //private int graphLength=DEFAULT_GRAPH_LENGTH; Unimplementable due to former developer's dark magic.
|
|
|
+
|
|
|
/*
|
|
|
* Energy at each point of the graph with 100 predefined points. At the
|
|
|
* beginning, it starts with all values at energyPerElement.
|
|
@@ -59,25 +65,24 @@ public class HolonElement {
|
|
|
* @param eleName String
|
|
|
* @param amount int
|
|
|
* @param energy float
|
|
|
+ * @param model Model
|
|
|
*/
|
|
|
+ public HolonElement(String eleName, int amount, float energy, Model model) {
|
|
|
+ this(eleName, amount, energy, IdCounterElem.nextId(),model);
|
|
|
+ }
|
|
|
+
|
|
|
public HolonElement(String eleName, int amount, float energy) {
|
|
|
- setEleName(eleName);
|
|
|
- setAmount(amount);
|
|
|
- setEnergyPerElement(energy);
|
|
|
- setActive(true);
|
|
|
- setSign(energy);
|
|
|
- setAvailableEnergyPerElementAt(energy);
|
|
|
- setGraphPoints(new LinkedList<>());
|
|
|
- setId(IdCounterElem.nextId());
|
|
|
- setFlexibleEnergyAvailable(0);
|
|
|
- setFlexible(false);
|
|
|
+ this(eleName, amount, energy, IdCounterElem.nextId(),null);//TODO: This is just for the old tests...
|
|
|
+ System.out.println("HELL NO");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* same as standard constructor, but with already given id (so the counter is not increased twice)
|
|
|
*/
|
|
|
- public HolonElement(String eleName, int amount, float energy, int id) {
|
|
|
- setEleName(eleName);
|
|
|
+ public HolonElement(String eleName, int amount, float energy, int id, Model model){
|
|
|
+ //if(model!=null)graphLength=model.getGraphIterations();
|
|
|
+ //if(graphLength==0)graphLength=DEFAULT_GRAPH_LENGTH;//To counter their constructor bypassing...
|
|
|
+ setEleName(eleName);
|
|
|
setAmount(amount);
|
|
|
setEnergyPerElement(energy);
|
|
|
setActive(true);
|
|
@@ -95,6 +100,7 @@ public class HolonElement {
|
|
|
* @param element element to copy
|
|
|
*/
|
|
|
public HolonElement(HolonElement element) {
|
|
|
+ //graphLength=element.graphLength;//Should I add a getter?
|
|
|
setEleName(element.getEleName());
|
|
|
setAmount(element.getAmount());
|
|
|
setEnergyPerElement(element.getEnergyPerElement());
|
|
@@ -151,7 +157,7 @@ public class HolonElement {
|
|
|
* Get the energyPerElement currently available
|
|
|
*/
|
|
|
public float getAvailableEnergyAt(int timestep) {
|
|
|
- return this.availableEnergyPerElementAt[timestep%100];//TODO: Since I added the modulo twice, something could be refactored here.
|
|
|
+ return this.availableEnergyPerElementAt[timestep%DEFAULT_GRAPH_LENGTH];//TODO:This would use the variable
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -259,7 +265,7 @@ public class HolonElement {
|
|
|
if (flexible) {
|
|
|
return ((float) amount) * energyPerElement;
|
|
|
} else {
|
|
|
- return ((float) amount) * availableEnergyPerElementAt[x%100];//TODO: Adapt graph length
|
|
|
+ return ((float) amount) * availableEnergyPerElementAt[x%DEFAULT_GRAPH_LENGTH];//TODO: Adapt graph length
|
|
|
}
|
|
|
}
|
|
|
|