Browse Source

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

Holt59 6 years ago
parent
commit
e0268c80af

+ 23
- 7
src/main/org/insa/graph/Arc.java View File

@@ -16,35 +16,51 @@ import java.util.List;
16 16
  * @see ArcBackward
17 17
  *
18 18
  */
19
-public interface Arc {
19
+public abstract class Arc {
20 20
 
21 21
     /**
22 22
      * @return Origin node of this arc.
23 23
      */
24
-    public Node getOrigin();
24
+    public abstract Node getOrigin();
25 25
 
26 26
     /**
27 27
      * @return Destination node of this arc.
28 28
      */
29
-    public Node getDestination();
29
+    public abstract Node getDestination();
30 30
 
31 31
     /**
32 32
      * @return Length of this arc, in meters.
33 33
      */
34
-    public float getLength();
34
+    public abstract double getLength();
35
+
36
+    /**
37
+     * Compute the time required to travel this arc if moving at the given speed.
38
+     * 
39
+     * @param speed Speed to compute the travel time.
40
+     * 
41
+     * @return Time (in seconds) required to travel this arc at the given speed (in
42
+     *         kilometers-per-hour).
43
+     */
44
+    public double getTravelTime(double speed) {
45
+        return getLength() * 3600.0 / (speed * 1000.0);
46
+    }
35 47
 
36 48
     /**
37 49
      * @return Minimum time required to travel this arc, in seconds.
50
+     * 
51
+     * @see Arc#getTravelTime(double)
38 52
      */
39
-    public double getMinimumTravelTime();
53
+    public double getMinimumTravelTime() {
54
+        return getTravelTime(getRoadInformation().getMaximumSpeed());
55
+    }
40 56
 
41 57
     /**
42 58
      * @return Road information for this arc.
43 59
      */
44
-    public RoadInformation getRoadInformation();
60
+    public abstract RoadInformation getRoadInformation();
45 61
 
46 62
     /**
47 63
      * @return Points representing segments of this arc.
48 64
      */
49
-    public List<Point> getPoints();
65
+    public abstract List<Point> getPoints();
50 66
 }

+ 2
- 7
src/main/org/insa/graph/ArcBackward.java View File

@@ -10,7 +10,7 @@ import java.util.List;
10 10
  * the original arc.
11 11
  *
12 12
  */
13
-class ArcBackward implements Arc {
13
+class ArcBackward extends Arc {
14 14
 
15 15
     // Original arc
16 16
     private final ArcForward originalArc;
@@ -37,16 +37,11 @@ class ArcBackward implements Arc {
37 37
     }
38 38
 
39 39
     @Override
40
-    public float getLength() {
40
+    public double getLength() {
41 41
         return this.originalArc.getLength();
42 42
     }
43 43
 
44 44
     @Override
45
-    public double getMinimumTravelTime() {
46
-        return this.originalArc.getMinimumTravelTime();
47
-    }
48
-
49
-    @Override
50 45
     public RoadInformation getRoadInformation() {
51 46
         return this.originalArc.getRoadInformation();
52 47
     }

+ 2
- 7
src/main/org/insa/graph/ArcForward.java View File

@@ -9,7 +9,7 @@ import java.util.List;
9 9
  * arc implementation that stores data relative to the arc.
10 10
  *
11 11
  */
12
-class ArcForward implements Arc {
12
+class ArcForward extends Arc {
13 13
 
14 14
     // Destination node.
15 15
     private final Node origin, destination;
@@ -52,16 +52,11 @@ class ArcForward implements Arc {
52 52
     }
53 53
 
54 54
     @Override
55
-    public float getLength() {
55
+    public double getLength() {
56 56
         return length;
57 57
     }
58 58
 
59 59
     @Override
60
-    public double getMinimumTravelTime() {
61
-        return getLength() * 3600.0 / (info.getMaximumSpeed() * 1000.0);
62
-    }
63
-
64
-    @Override
65 60
     public RoadInformation getRoadInformation() {
66 61
         return info;
67 62
     }

Loading…
Cancel
Save