-
Notifications
You must be signed in to change notification settings - Fork 0
/
Route.java
189 lines (159 loc) · 5.94 KB
/
Route.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package homework1;
import java.util.Iterator;
/**
* A Route is a path that traverses arbitrary GeoSegments, regardless
* of their names.
* <p>
* Routes are immutable. New Routes can be constructed by adding a segment
* to the end of a Route. An added segment must be properly oriented; that
* is, its p1 field must correspond to the end of the original Route, and
* its p2 field corresponds to the end of the new Route.
* <p>
* Because a Route is not necessarily straight, its length - the distance
* traveled by following the path from start to end - is not necessarily
* the same as the distance along a straight line between its endpoints.
* <p>
* Lastly, a Route may be viewed as a sequence of geographical features,
* using the <tt>getGeoFeatures()</tt> method which returns an Iterator of
* GeoFeature objects.
* <p>
* <b>The following fields are used in the specification:</b>
* <pre>
* start : GeoPoint // location of the start of the route
* end : GeoPoint // location of the end of the route
* startHeading : angle // direction of travel at the start of the route, in degrees
* endHeading : angle // direction of travel at the end of the route, in degrees
* geoFeatures : sequence // a sequence of geographic features that make up this Route
* geoSegments : sequence // a sequence of segments that make up this Route
* length : real // total length of the route, in kilometers
* endingGeoSegment : GeoSegment // last GeoSegment of the route
* </pre>
**/
public class Route {
// TODO Write abstraction function and representation invariant
/**
* Constructs a new Route.
* @requires gs != null
* @effects Constructs a new Route, r, such that
* r.startHeading = gs.heading &&
* r.endHeading = gs.heading &&
* r.start = gs.p1 &&
* r.end = gs.p2
**/
public Route(GeoSegment gs) {
// TODO Implement this constructor
}
/**
* Returns location of the start of the route.
* @return location of the start of the route.
**/
public GeoPoint getStart() {
// TODO Implement this method
}
/**
* Returns location of the end of the route.
* @return location of the end of the route.
**/
public GeoPoint getEnd() {
// TODO Implement this method
}
/**
* Returns direction of travel at the start of the route, in degrees.
* @return direction (in compass heading) of travel at the start of the
* route, in degrees.
**/
public double getStartHeading() {
// TODO Implement this method
}
/**
* Returns direction of travel at the end of the route, in degrees.
* @return direction (in compass heading) of travel at the end of the
* route, in degrees.
**/
public double getEndHeading() {
// TODO Implement this method
}
/**
* Returns total length of the route.
* @return total length of the route, in kilometers. NOTE: this is NOT
* as-the-crow-flies, but rather the total distance required to
* traverse the route. These values are not necessarily equal.
**/
public double getLength() {
// TODO Implement this method
}
/**
* Creates a new route that is equal to this route with gs appended to
* its end.
* @requires gs != null && gs.p1 == this.end
* @return a new Route r such that
* r.end = gs.p2 &&
* r.endHeading = gs.heading &&
* r.length = this.length + gs.length
**/
public Route addSegment(GeoSegment gs) {
// TODO Implement this method
}
/**
* Returns an Iterator of GeoFeature objects. The concatenation
* of the GeoFeatures, in order, is equivalent to this route. No two
* consecutive GeoFeature objects have the same name.
* @return an Iterator of GeoFeatures such that
* <pre>
* this.start = a[0].start &&
* this.startHeading = a[0].startHeading &&
* this.end = a[a.length - 1].end &&
* this.endHeading = a[a.length - 1].endHeading &&
* this.length = sum(0 <= i < a.length) . a[i].length &&
* for all integers i
* (0 <= i < a.length - 1 => (a[i].name != a[i+1].name &&
* a[i].end == a[i+1].start))
* </pre>
* where <code>a[n]</code> denotes the nth element of the Iterator.
* @see homework1.GeoFeature
**/
public Iterator<GeoFeature> getGeoFeatures() {
// TODO Implement this method
}
/**
* Returns an Iterator of GeoSegment objects. The concatenation of the
* GeoSegments, in order, is equivalent to this route.
* @return an Iterator of GeoSegments such that
* <pre>
* this.start = a[0].p1 &&
* this.startHeading = a[0].heading &&
* this.end = a[a.length - 1].p2 &&
* this.endHeading = a[a.length - 1].heading &&
* this.length = sum (0 <= i < a.length) . a[i].length
* </pre>
* where <code>a[n]</code> denotes the nth element of the Iterator.
* @see homework1.GeoSegment
**/
public Iterator<GeoSegment> getGeoSegments() {
// TODO Implement this method
}
/**
* Compares the specified Object with this Route for equality.
* @return true iff (o instanceof Route) &&
* (o.geoFeatures and this.geoFeatures contain
* the same elements in the same order).
**/
public boolean equals(Object o) {
// TODO Implement this method
}
/**
* Returns a hash code for this.
* @return a hash code for this.
**/
public int hashCode() {
// This implementation will work, but you may want to modify it
// for improved performance.
return 1;
}
/**
* Returns a string representation of this.
* @return a string representation of this.
**/
public String toString() {
}
}