Commit e45b26cf authored by Jakob Schöttl's avatar Jakob Schöttl

Refactor ScenarioElement

- class instead of interface for technical reasons
- use standard implementation of clone
- inherit standard clone method from base class
parent 5d2cf664
......@@ -20,7 +20,7 @@ import org.vadere.util.geometry.shapes.VShape;
*
*
*/
public final class AgentWrapper implements ScenarioElement {
public final class AgentWrapper extends ScenarioElement {
/** we only need the radius from the attributes. */
private final AttributesAgent attributes;
......@@ -67,11 +67,6 @@ public final class AgentWrapper implements ScenarioElement {
return ScenarioElementType.PEDESTRIAN;
}
@Override
public AgentWrapper clone() {
return new AgentWrapper(this);
}
@Override
public Attributes getAttributes() {
return attributes;
......
......@@ -14,7 +14,7 @@ import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.math.TruncatedNormalDistribution;
public abstract class Agent implements DynamicElement {
public abstract class Agent extends DynamicElement {
/**
* Source where the agent was spawned. The {@link SourceController} should
......@@ -113,9 +113,6 @@ public abstract class Agent implements DynamicElement {
return attributes.getId();
}
@Override
public abstract Agent clone();
/**
* Converts a Iterable of Agent to a List of VPoint positions.
*
......
......@@ -2,5 +2,5 @@ package org.vadere.state.scenario;
import org.vadere.util.geometry.PointPositioned;
public interface DynamicElement extends ScenarioElement, PointPositioned {
public abstract class DynamicElement extends ScenarioElement implements PointPositioned {
}
......@@ -5,7 +5,7 @@ import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public class Obstacle implements ScenarioElement {
public class Obstacle extends ScenarioElement {
private final AttributesObstacle attributes;
......@@ -16,14 +16,6 @@ public class Obstacle implements ScenarioElement {
this.attributes = attributes;
}
/**
* Returns a copy of this obstacle with the same attributes.
*/
@Override
public Obstacle clone() {
return new Obstacle(attributes);
}
@Override
public VShape getShape() {
return attributes.getShape();
......
......@@ -4,19 +4,32 @@ import org.vadere.state.attributes.Attributes;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public interface ScenarioElement extends Cloneable {
public abstract class ScenarioElement implements Cloneable {
VShape getShape();
public abstract VShape getShape();
default void setShape(VShape newShape) {
public void setShape(VShape newShape) {
throw new UnsupportedOperationException("This concrete scenario element does not support setting the shape.");
}
int getId();
public abstract int getId();
ScenarioElementType getType();
public abstract ScenarioElementType getType();
ScenarioElement clone();
/**
* Redeclare the clone method as public to enable copy & paste of scenario
* elements in scenario editor.
*/
@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);
}
}
Attributes getAttributes();
public abstract Attributes getAttributes();
}
......@@ -4,7 +4,7 @@ import org.vadere.state.attributes.scenario.AttributesSource;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public class Source implements ScenarioElement {
public class Source extends ScenarioElement {
private final AttributesSource attributes;
......@@ -12,15 +12,6 @@ public class Source implements ScenarioElement {
this.attributes = attributes;
}
/**
* Creates a new source with the same attribute as this one, but no
* pedestrianAddListeners.
*/
@Override
public Source clone() {
return new Source(attributes);
}
@Override
public VShape getShape() {
return attributes.getShape();
......
......@@ -12,7 +12,7 @@ import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VShape;
public class Stairs implements ScenarioElement {
public class Stairs extends ScenarioElement {
public static class Tread {
public final VLine treadline;
......@@ -64,14 +64,6 @@ public class Stairs implements ScenarioElement {
return treadsResult;
}
/**
* Returns this {@link Stairs} object, which is immutable.
*/
@Override
public Stairs clone() {
return this;
}
@Override
public VShape getShape() {
return attributes.getShape();
......
......@@ -10,7 +10,7 @@ import org.vadere.state.attributes.scenario.AttributesTarget;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VShape;
public class Target implements ScenarioElement, Comparable<Target> {
public class Target extends ScenarioElement implements Comparable<Target> {
private final AttributesTarget attributes;
private final Map<Integer, Double> enteringTimes;
......@@ -68,15 +68,6 @@ public class Target implements ScenarioElement, Comparable<Target> {
return attributes.getShape();
}
/**
* Returns a new target with the same attributes as this one, but no
* {@link org.vadere.state.scenario.DynamicElementRemoveListener}.
*/
@Override
public Target clone() {
return new Target(attributes);
}
@Override
public int hashCode() {
final int prime = 31;
......
......@@ -6,7 +6,7 @@ import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
public class Teleporter implements ScenarioElement {
public class Teleporter extends ScenarioElement {
private final AttributesTeleporter attributes;
......@@ -22,11 +22,6 @@ public class Teleporter implements ScenarioElement {
return this.attributes.getTeleporterPosition();
}
@Override
public Teleporter clone() {
return new Teleporter(attributes);
}
@Override
public VShape getShape() {
throw new UnsupportedOperationException("A teleporter does not have a shape.");
......
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