-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeoFeature.java
193 lines (163 loc) · 6.33 KB
/
GeoFeature.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
190
191
192
193
package homework1;
import java.util.Iterator;
/**
* A GeoFeature represents a route from one location to another along a
* single geographic feature. GeoFeatures are immutable.
* <p>
* GeoFeature abstracts over a sequence of GeoSegments, all of which have
* the same name, thus providing a representation for nonlinear or nonatomic
* geographic features. As an example, a GeoFeature might represent the
* course of a winding river, or travel along a road through intersections
* but remaining on the same road.
* <p>
* GeoFeatures are immutable. New GeoFeatures can be constructed by adding
* a segment to the end of a GeoFeature. An added segment must be properly
* oriented; that is, its p1 field must correspond to the end of the original
* GeoFeature, and its p2 field corresponds to the end of the new GeoFeature,
* and the name of the GeoSegment being added must match the name of the
* existing GeoFeature.
* <p>
* Because a GeoFeature 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>
* <b>The following fields are used in the specification:</b>
* <pre>
* start : GeoPoint // location of the start of the geographic feature
* end : GeoPoint // location of the end of the geographic feature
* startHeading : angle // direction of travel at the start of the geographic feature, in degrees
* endHeading : angle // direction of travel at the end of the geographic feature, in degrees
* geoSegments : sequence // a sequence of segments that make up this geographic feature
* name : String // name of geographic feature
* length : real // total length of the geographic feature, in kilometers
* </pre>
**/
public class GeoFeature {
// Implementation hint:
// When asked to return an Iterator, consider using the iterator() method
// in the List interface. Two nice classes that implement the List
// interface are ArrayList and LinkedList. If comparing two Lists for
// equality is needed, consider using the equals() method of List. More
// info can be found at:
// http://docs.oracle.com/javase/8/docs/api/java/util/List.html
// TODO Write abstraction function and representation invariant
/**
* Constructs a new GeoFeature.
* @requires gs != null
* @effects Constructs a new GeoFeature, r, such that
* r.name = gs.name &&
* r.startHeading = gs.heading &&
* r.endHeading = gs.heading &&
* r.start = gs.p1 &&
* r.end = gs.p2
**/
public GeoFeature(GeoSegment gs) {
// TODO Implement this constructor
}
/**
* Returns name of geographic feature.
* @return name of geographic feature
*/
public String getName() {
// TODO Implement this method
}
/**
* Returns location of the start of the geographic feature.
* @return location of the start of the geographic feature.
*/
public GeoPoint getStart() {
// TODO Implement this method
}
/**
* Returns location of the end of the geographic feature.
* @return location of the end of the geographic feature.
*/
public GeoPoint getEnd() {
// TODO Implement this method
}
/**
* Returns direction of travel at the start of the geographic feature.
* @return direction (in standard heading) of travel at the start of the
* geographic feature, in degrees.
*/
public double getStartHeading() {
// TODO Implement this method
}
/**
* Returns direction of travel at the end of the geographic feature.
* @return direction (in standard heading) of travel at the end of the
* geographic feature, in degrees.
*/
public double getEndHeading() {
// TODO Implement this method
}
/**
* Returns total length of the geographic feature, in kilometers.
* @return total length of the geographic feature, in kilometers.
* NOTE: this is NOT as-the-crow-flies, but rather the total
* distance required to traverse the geographic feature. These
* values are not necessarily equal.
*/
public double getLength() {
// TODO Implement this method
}
/**
* Creates a new GeoFeature that is equal to this GeoFeature with gs
* appended to its end.
* @requires gs != null && gs.p1 = this.end && gs.name = this.name.
* @return a new GeoFeature r such that
* r.end = gs.p2 &&
* r.endHeading = gs.heading &&
* r.length = this.length + gs.length
**/
public GeoFeature addSegment(GeoSegment gs) {
// TODO Implement this method
}
/**
* Returns an Iterator of GeoSegment objects. The concatenation of the
* GeoSegments, in order, is equivalent to this GeoFeature. All the
* GeoSegments have the same name.
* @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 &&
* for all integers i
* (0 <= i < a.length-1 => (a[i].name == a[i+1].name &&
* a[i].p2d == a[i+1].p1))
* </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 argument with this GeoFeature for equality.
* @return o != null && (o instanceof GeoFeature) &&
* (o.geoSegments and this.geoSegments 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
// improved performance.
return 1;
}
/**
* Returns a string representation of this.
* @return a string representation of this.
**/
public String toString() {
// TODO Implement this method
}
}