Commit 173391e0 authored by Jakob Schöttl's avatar Jakob Schöttl

Refactor while searching for a bug

parent 081b8d57
......@@ -31,7 +31,7 @@ public abstract class Agent implements DynamicElement {
private double freeFlowSpeed;
private AttributesAgent attributes;
private final AttributesAgent attributes;
public Agent(AttributesAgent attributesAgent) {
position = new VPoint(0, 0);
......
......@@ -12,13 +12,13 @@ import org.vadere.util.geometry.shapes.VRectangle;
public class Car extends Agent implements Comparable<Car> {
private AttributesCar attributesCar;
private final AttributesCar attributesCar;
private transient Random random;
public Car(AttributesCar attributesCar, Random random) {
super(attributesCar, random);
this.setAttributesCar(attributesCar);
this.attributesCar = attributesCar;
setPosition(new VPoint(0, 0));
setVelocity(new Vector2D(0, 0));
// this.targetIds = new LinkedList<>();
......@@ -36,11 +36,6 @@ public class Car extends Agent implements Comparable<Car> {
setTargets(new LinkedList<>(other.getTargets()));
}
public void setAttributesCar(AttributesCar attributesCar) {
this.attributesCar = attributesCar;
}
@Override
public int compareTo(Car o) {
Double thisPos = new Double(getPosition().getX());
......
......@@ -72,7 +72,7 @@ public class Topography {
allOtherAttributes.add(attributes);
allOtherAttributes.add(attributesCar);
allOtherAttributes.add(attributesPedestrian);
removeNullAttributesFrom(allOtherAttributes);
removeNullFromSet(allOtherAttributes);
obstacles = new LinkedList<>();
stairs = new LinkedList<>();
......@@ -85,6 +85,7 @@ public class Topography {
allScenarioElements.add(sources);
allScenarioElements.add(targets);
allScenarioElements.add(boundaryObstacles);
removeNullFromSet(allScenarioElements);
RectangularShape bounds = this.getBounds();
......@@ -93,9 +94,9 @@ public class Topography {
}
/** Clean up the list of attributes by removing {@code null}. */
private void removeNullAttributesFrom(Set<Attributes> allOtherAttributes) {
allOtherAttributes.remove(null);
/** Clean up a set by removing {@code null}. */
private void removeNullFromSet(Set<?> aSet) {
aSet.remove(null);
// Actually, only attributes, not nulls should be added to this set.
// But sometimes null is passed as attributes and added to the set,
// although it is bad practice to pass null in the first place
......@@ -237,8 +238,11 @@ public class Topography {
}
public void setTeleporter(Teleporter teleporter) {
allScenarioElements.remove(this.teleporter); // remove old teleporter
this.teleporter = teleporter;
allScenarioElements.add(Collections.singletonList(teleporter));
if (teleporter != null)
allScenarioElements.add(Collections.singletonList(teleporter));
}
public <T extends DynamicElement> void addInitialElement(T element) {
......@@ -409,6 +413,12 @@ public class Topography {
public void sealAllAttributes() {
// tried to do this with flatMap -> weird compiler error "cannot infer type arguments ..."
for (List<? extends ScenarioElement> list : allScenarioElements) {
if (list == null)
throw new RuntimeException("scenario elem list is null");
for (ScenarioElement scenarioElement : list) {
if (scenarioElement.getAttributes() != null)
throw new RuntimeException("scenario elem attr are null: " + scenarioElement);
}
list.forEach(se -> se.getAttributes().seal());
}
allOtherAttributes.forEach(a -> a.seal());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment