The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit 4f85fecf authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Change implementation of clone in ScenarioElements

parent 8077e613
......@@ -22,7 +22,7 @@ import org.vadere.util.geometry.shapes.VShape;
*/
public final class AgentWrapper extends ScenarioElement {
/** the wrapped store object. */
/** The wrapped store object. */
private Agent agent;
AgentWrapper(final VPoint position) {
......@@ -70,4 +70,10 @@ public final class AgentWrapper extends ScenarioElement {
public Attributes getAttributes() {
return agent.getAttributes();
}
@Override
public AgentWrapper clone() {
return new AgentWrapper((Agent) agent.clone());
}
}
......@@ -317,5 +317,10 @@ public class PedestrianOSM extends Pedestrian {
public double getMinStepLength() {
return minStepLength;
}
@Override
public PedestrianOSM clone() {
throw new RuntimeException("clone is not supported for PedestrianOSM; it seems hard to implement.");
}
}
......@@ -13,4 +13,10 @@ public class TargetQueue extends Target {
public boolean isMovingTarget() {
return true;
}
@Override
public TargetQueue clone() {
throw new RuntimeException("clone is not supported for TargetQueue; it seems hard to implement.");
}
}
......@@ -21,5 +21,14 @@ public abstract class Attributes extends DefaultSealable implements Cloneable {
protected static final int ID_NOT_SET = -1;
public Attributes() {}
@Override
public Attributes clone() {
try {
return (Attributes) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("This should never happen because the base class is Cloneable.", e);
}
}
}
......@@ -68,4 +68,12 @@ public class Car extends Agent implements Comparable<Car> {
return attributesCar.getId();
}
@Override
public Car clone() {
throw new RuntimeException("clone is not supported for Car; it seems hard to implement.");
// return new Car(attributesCar, new Random());
// TODO get random from super class instead of creating a new one
// TODO attributesAgent in super class must be copied as well
}
}
......@@ -70,4 +70,9 @@ public class Obstacle extends ScenarioElement {
public Attributes getAttributes() {
return attributes;
}
@Override
public Obstacle clone() {
return new Obstacle((AttributesObstacle) attributes.clone());
}
}
......@@ -112,4 +112,10 @@ public class Pedestrian extends Agent {
public void setLikelyInjured(boolean likelyInjured) {
this.isLikelyInjured = likelyInjured;
}
@Override
public Pedestrian clone() {
return new Pedestrian(this);
}
}
......@@ -4,7 +4,7 @@ import org.vadere.state.attributes.Attributes;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public abstract class ScenarioElement implements Cloneable {
public abstract class ScenarioElement {
public abstract VShape getShape();
......@@ -19,17 +19,10 @@ public abstract class ScenarioElement implements Cloneable {
/**
* Redeclare the clone method as public to enable copy & paste of scenario
* elements in scenario editor.
* Subclasses must implement this method using a copy constructor.
*/
@Override
public ScenarioElement clone() {
try {
return (ScenarioElement) super.clone();
} catch (CloneNotSupportedException e) {
// this case should never happen (because this base class is cloneable)
// unless a subclass contains not-cloneable fields or so
throw new RuntimeException(e);
}
}
public abstract ScenarioElement clone();
public abstract Attributes getAttributes();
}
......@@ -71,4 +71,9 @@ public class Source extends ScenarioElement {
public ScenarioElementType getType() {
return ScenarioElementType.SOURCE;
}
@Override
public Source clone() {
return new Source((AttributesSource) attributes.clone());
}
}
......@@ -126,4 +126,10 @@ public class Stairs extends ScenarioElement {
public AttributesStairs getAttributes() {
return attributes;
}
@Override
public Stairs clone() {
return new Stairs((AttributesStairs) attributes.clone());
}
}
......@@ -141,4 +141,9 @@ public class Target extends ScenarioElement implements Comparable<Target> {
return Collections.unmodifiableCollection(targetListeners);
}
@Override
public Target clone() {
return new Target((AttributesTarget) attributes.clone());
}
}
......@@ -60,4 +60,10 @@ public class TargetPedestrian extends Target implements DynamicElementRemoveList
return true;
}
@Override
public TargetPedestrian clone() {
throw new RuntimeException("clone is not supported for TargetPedestrian; it seems hard to implement.");
}
}
......@@ -61,4 +61,10 @@ public class Teleporter extends ScenarioElement {
public int hashCode() {
return attributes != null ? attributes.hashCode() : 0;
}
@Override
public Teleporter clone() {
return new Teleporter((AttributesTeleporter) attributes.clone());
}
}
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