6.5.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 0ecc2ddd authored by Jakob Schöttl's avatar Jakob Schöttl

Simplify and fix code for cloning

parent de80d934
...@@ -338,41 +338,45 @@ public class Topography { ...@@ -338,41 +338,45 @@ public class Topography {
/** /**
* Creates a deep copy of the scenario. * Creates a deep copy of the scenario.
*
* @deprecated This manual implementation is error-prone. Remove this method
* and use the standard clone instead.
*/ */
@Deprecated
@Override @Override
public Topography clone() { public Topography clone() {
Topography s = new Topography(this.attributes, this.attributesPedestrian, this.attributesCar); Topography s = new Topography(this.attributes, this.attributesPedestrian, this.attributesCar);
for (Obstacle obstacle : this.getObstacles()) { for (Obstacle obstacle : this.getObstacles()) {
if (this.boundaryObstacles.contains(obstacle)) if (boundaryObstacles.contains(obstacle))
s.addBoundary(obstacle.clone()); s.addBoundary((Obstacle) obstacle.clone());
else else
s.addObstacle(obstacle.clone()); s.addObstacle((Obstacle) obstacle.clone());
} }
for (Stairs stairs : this.getStairs()) { for (Stairs stairs : getStairs()) {
s.addStairs(stairs); s.addStairs(stairs);
} }
for (Target target : this.getTargets()) { for (Target target : getTargets()) {
s.addTarget(target.clone()); s.addTarget((Target) target.clone());
} }
for (Source source : this.getSources()) { for (Source source : getSources()) {
s.addSource(source.clone()); s.addSource((Source) source.clone());
} }
for (Pedestrian pedestrian : this.getElements(Pedestrian.class)) { for (Pedestrian pedestrian : getElements(Pedestrian.class)) {
s.addElement(pedestrian); s.addElement(pedestrian);
} }
for (Pedestrian ped : getInitialElements(Pedestrian.class)) { for (Pedestrian ped : getInitialElements(Pedestrian.class)) {
s.addInitialElement(ped); s.addInitialElement(ped);
} }
for (Car car : this.getElements(Car.class)) { for (Car car : getElements(Car.class)) {
s.addElement(car); s.addElement(car);
} }
for (Car car : getInitialElements(Car.class)) { for (Car car : getInitialElements(Car.class)) {
s.addInitialElement(car); s.addInitialElement(car);
} }
if (this.hasTeleporter()) { if (hasTeleporter()) {
s.setTeleporter(this.getTeleporter().clone()); s.setTeleporter((Teleporter) teleporter.clone());
} }
for (DynamicElementAddListener<Pedestrian> pedestrianAddListener : this.pedestrians.getElementAddedListener()) { for (DynamicElementAddListener<Pedestrian> pedestrianAddListener : this.pedestrians.getElementAddedListener()) {
......
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