Fix Arc and add @deprecated javadoc for students to implement.

This commit is contained in:
Holt59 2018-03-09 21:26:38 +01:00
parent 440dc48c6a
commit e0268c80af
3 changed files with 27 additions and 21 deletions

View file

@ -16,35 +16,51 @@ import java.util.List;
* @see ArcBackward
*
*/
public interface Arc {
public abstract class Arc {
/**
* @return Origin node of this arc.
*/
public Node getOrigin();
public abstract Node getOrigin();
/**
* @return Destination node of this arc.
*/
public Node getDestination();
public abstract Node getDestination();
/**
* @return Length of this arc, in meters.
*/
public float getLength();
public abstract double getLength();
/**
* Compute the time required to travel this arc if moving at the given speed.
*
* @param speed Speed to compute the travel time.
*
* @return Time (in seconds) required to travel this arc at the given speed (in
* kilometers-per-hour).
*/
public double getTravelTime(double speed) {
return getLength() * 3600.0 / (speed * 1000.0);
}
/**
* @return Minimum time required to travel this arc, in seconds.
*
* @see Arc#getTravelTime(double)
*/
public double getMinimumTravelTime();
public double getMinimumTravelTime() {
return getTravelTime(getRoadInformation().getMaximumSpeed());
}
/**
* @return Road information for this arc.
*/
public RoadInformation getRoadInformation();
public abstract RoadInformation getRoadInformation();
/**
* @return Points representing segments of this arc.
*/
public List<Point> getPoints();
public abstract List<Point> getPoints();
}

View file

@ -10,7 +10,7 @@ import java.util.List;
* the original arc.
*
*/
class ArcBackward implements Arc {
class ArcBackward extends Arc {
// Original arc
private final ArcForward originalArc;
@ -37,15 +37,10 @@ class ArcBackward implements Arc {
}
@Override
public float getLength() {
public double getLength() {
return this.originalArc.getLength();
}
@Override
public double getMinimumTravelTime() {
return this.originalArc.getMinimumTravelTime();
}
@Override
public RoadInformation getRoadInformation() {
return this.originalArc.getRoadInformation();

View file

@ -9,7 +9,7 @@ import java.util.List;
* arc implementation that stores data relative to the arc.
*
*/
class ArcForward implements Arc {
class ArcForward extends Arc {
// Destination node.
private final Node origin, destination;
@ -52,15 +52,10 @@ class ArcForward implements Arc {
}
@Override
public float getLength() {
public double getLength() {
return length;
}
@Override
public double getMinimumTravelTime() {
return getLength() * 3600.0 / (info.getMaximumSpeed() * 1000.0);
}
@Override
public RoadInformation getRoadInformation() {
return info;