- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGraphLoader.java
More file actions
Latest commit
executable file
·716 lines (628 loc) · 23.1 KB
/
Copy pathGraphLoader.java
File metadata and controls
executable file
·716 lines (628 loc) · 23.1 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
/**
* @author UCSD Intermediate Programming MOOC team
*
* A utility class that reads various kinds of files into different
* graph structures.
*/
packageutil;
importjava.io.BufferedReader;
importjava.io.FileReader;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.util.ArrayList;
importjava.util.Collection;
importjava.util.HashMap;
importjava.util.HashSet;
importjava.util.LinkedList;
importjava.util.List;
importjava.util.Set;
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
importbasicgraph.Graph;
importgeography.GeographicPoint;
importgeography.RoadSegment;
importroadgraph.MapGraph;
publicclassGraphLoader
{
/**
* * The file contains data lines as follows:
* lat1 lon1 lat2 lon2 roadName roadType
*
* where each line is a segment of a road
* These road segments are assumed to be ONE WAY.
*
* This method will collapse the points so that only intersections
* are represented as nodes in the graph.
*
* @param roadDataFile The file containing the road data, in the format
* described.
* @param intersectionsFile The output file containing the intersections.
*/
publicstaticvoidcreateIntersectionsFile(StringroadDataFile, StringintersectionsFile)
{
Collection<GeographicPoint> nodes = newHashSet<GeographicPoint>();
HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap =
buildPointMapOneWay(roadDataFile);
// Print the intersections to the file
List<GeographicPoint> intersections = findIntersections(pointMap);
for (GeographicPointpt : intersections) {
nodes.add(pt);
}
try {
PrintWriterwriter = newPrintWriter(intersectionsFile, "UTF-8");
// Now we need to add the edges
// This is the tricky part
for (GeographicPointpt : nodes) {
// Trace the node to its next node, building up the points
// on the edge as you go.
List<LinkedList<RoadLineInfo>> inAndOut = pointMap.get(pt);
LinkedList<RoadLineInfo> outgoing = inAndOut.get(0);
for (RoadLineInfoinfo : outgoing) {
HashSet<GeographicPoint> used = newHashSet<GeographicPoint>();
used.add(pt);
List<GeographicPoint> pointsOnEdge =
findPointsOnEdge(pointMap, info, nodes);
GeographicPointend = pointsOnEdge.remove(pointsOnEdge.size()-1);
writer.println(pt + " " + end);
}
}
writer.flush();
writer.close();
}
catch (Exceptione) {
System.out.println("Exception opening intersections file " + e);
}
}
/**
*
* Read in a file specifying a map.
*
* The file contains data lines as follows:
* lat1 lon1 lat2 lon2 roadName roadType
*
* where each line is a segment of a road
* These road segments are assumed to be ONE WAY.
*
* This method will collapse the points so that only intersections
* are represented as nodes in the graph.
*
* @param filename The file containing the road data, in the format
* described.
* @param map The graph to load the map into. The graph is
* assumed to be directed.
* @param segments The collection of RoadSegments that define the
* shape of a road. These segments are maintained separately from
* the graph as they are only used to display paths.
*/
publicstaticvoidloadRoadMap(Stringfilename, roadgraph.MapGraphmap)
{
loadRoadMap(filename, map, null, null);
}
/**
* Read in a file specifying a map.
*
* The file contains data lines as follows:
* lat1 lon1 lat2 lon2 roadName roadType
*
* where each line is a segment of a road
* These road segments are assumed to be ONE WAY.
*
* This method will collapse the points so that only intersections
* are represented as nodes in the graph.
*
* @param filename The file containing the road data, in the format
* described.
* @param map The graph to load the map into. The graph is
* assumed to be directed.
*/
publicstaticvoidloadRoadMap(Stringfilename, roadgraph.MapGraphmap,
HashMap<GeographicPoint,HashSet<RoadSegment>> segments,
Set<GeographicPoint> intersectionsToLoad)
{
Collection<GeographicPoint> nodes = newHashSet<GeographicPoint>();
HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap =
buildPointMapOneWay(filename);
// Add the nodes to the graph
List<GeographicPoint> intersections = findIntersections(pointMap);
for (GeographicPointpt : intersections) {
map.addVertex(pt);
if (intersectionsToLoad != null) {
intersectionsToLoad.add(pt);
}
nodes.add(pt);
}
addEdgesAndSegments(nodes, pointMap, map, segments);
}
/**
*
* Read in a file specifying a map.
*
* The file contains data lines as follows:
* lat1 lon1 lat2 lon2 roadName roadType
*
* where each line is a segment of a road
* These road segments are assumed to be ONE WAY.
*
* This method will collapse the points so that only intersections
* are represented as nodes in the graph.
*
* @param filename The file containing the road data, in the format
* described.
* @param theGraph The graph to load the map into. The graph is
* assumed to be directed.
*/
publicstaticvoidloadRoadMap(Stringfilename, basicgraph.GraphtheGraph)
{
HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap =
buildPointMapOneWay(filename);
HashMap<Integer,GeographicPoint> vertexMap =
newHashMap<Integer,GeographicPoint>();
HashMap<GeographicPoint,Integer> reverseMap =
newHashMap<GeographicPoint,Integer>();
// Add the nodes to the graph
List<GeographicPoint> intersections = findIntersections(pointMap);
intindex = 0;
for (GeographicPointpt : intersections) {
theGraph.addVertex();
vertexMap.put(index, pt);
reverseMap.put(pt, index);
index++;
}
// Now add the edges
Collection<Integer> nodes = vertexMap.keySet();
for (IntegernodeNum : nodes) {
// Trace the node to its next node, building up the points
// on the edge as you go.
GeographicPointpt = vertexMap.get(nodeNum);
List<LinkedList<RoadLineInfo>> inAndOut = pointMap.get(pt);
List<RoadLineInfo> infoList = inAndOut.get(0);
for (RoadLineInfoinfo : infoList) {
GeographicPointend = findEndOfEdge(pointMap, info, theGraph,
reverseMap);
IntegerendNum = reverseMap.get(end);
theGraph.addEdge(nodeNum, endNum);
}
}
}
/** Read in a file specifying route maps between airports.
* The file contains data as follows:
* Airline, AirlineID, Source airport, Source airport ID,
* Destination airport, Destination airport ID, Codeshare, Stops, Equipment
* This method will only read in nonstop routes (with Stops == 0)
* Vertices are airports (labeled with Strings)
* Edges represent nonstop routes
* @param filename
* @param graph
*/
publicstaticvoidloadRoutes(Stringfilename, Graphgraph)
{
Stringsource;
Stringdestination;
intsourceIndex;
intdestinationIndex;
intlineCount = 0; //for debugging
//Initialize vertex label HashMap in graph
graph.initializeLabels();
//Read in flights from file
BufferedReaderreader = null;
try {
StringnextLine;
reader = newBufferedReader(newFileReader(filename));
while ((nextLine = reader.readLine()) != null) {
String[] flightInfo = nextLine.split(",");
// //Only count nonstop flights
// if (Integer.parseInt(flightInfo[7])==0) {
source = flightInfo[2];
destination = flightInfo[4];
//Add edge for this flight, if both source & destination are already vertices.
//If one of these airports is missing, add vertex for it and then place edge.
if (!graph.hasVertex(source)) {
sourceIndex = graph.addVertex();
graph.addLabel(sourceIndex, source);
}
else {
sourceIndex = graph.getIndex(source);
}
if (!graph.hasVertex(destination)) {
destinationIndex = graph.addVertex();
graph.addLabel(destinationIndex, destination);
}
else {
destinationIndex = graph.getIndex(destination);
}
graph.addEdge(sourceIndex, destinationIndex);
}
lineCount ++;
// }
reader.close();
} catch (IOExceptione) {
System.err.println("Problem loading route file: " + filename);
e.printStackTrace();
}
}
/**
* Loads a graph from a file. The file is specified with each
* line representing an edge. Vertices are numbered from
* 0..1-numVertices.
*
* The first line of the file contains a single int which is the
* number of vertices in the graph.
* e.g.
* 5
* 1 3
* 3 2
* 3 5
* 5 4
*
* @param filename The file containing the graph
* @param theGraph The graph to be loaded
*/
publicstaticvoidloadGraph(Stringfilename, basicgraph.GraphtheGraph)
{
BufferedReaderreader = null;
try {
StringnextLine;
reader = newBufferedReader(newFileReader(filename));
nextLine = reader.readLine();
if (nextLine == null) {
reader.close();
thrownewIOException("Graph file is empty!");
}
intnumVertices = Integer.parseInt(nextLine);
for (inti = 0; i < numVertices; i++) {
theGraph.addVertex();
}
// Read the lines out of the file and put them in a HashMap by points
while ((nextLine = reader.readLine()) != null) {
String[] verts = nextLine.split(" ");
intstart = Integer.parseInt(verts[0]);
intend = Integer.parseInt(verts[1]);
theGraph.addEdge(start, end);
}
reader.close();
} catch (IOExceptione) {
System.err.println("Problem loading graph file: " + filename);
e.printStackTrace();
}
}
// Once you have built the pointMap and added the Nodes,
// add the edges and build the road segments if the segments
// map is not null.
privatestaticvoidaddEdgesAndSegments(Collection<GeographicPoint> nodes,
HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap,
MapGraphmap,
HashMap<GeographicPoint,HashSet<RoadSegment>> segments)
{
// Now we need to add the edges
// This is the tricky part
for (GeographicPointpt : nodes) {
// Trace the node to its next node, building up the points
// on the edge as you go.
List<LinkedList<RoadLineInfo>> inAndOut = pointMap.get(pt);
LinkedList<RoadLineInfo> outgoing = inAndOut.get(0);
for (RoadLineInfoinfo : outgoing) {
HashSet<GeographicPoint> used = newHashSet<GeographicPoint>();
used.add(pt);
List<GeographicPoint> pointsOnEdge =
findPointsOnEdge(pointMap, info, nodes);
GeographicPointend = pointsOnEdge.remove(pointsOnEdge.size()-1);
doublelength = getRoadLength(pt, end, pointsOnEdge);
map.addEdge(pt, end, info.roadName, info.roadType, length);
// If the segments variable is not null, then we
// save the road geometry
if (segments != null) {
// Now create road Segments for each edge
HashSet<RoadSegment> segs = segments.get(pt);
if (segs == null) {
segs = newHashSet<RoadSegment>();
segments.put(pt,segs);
}
RoadSegmentseg = newRoadSegment(pt, end, pointsOnEdge,
info.roadName, info.roadType, length);
segs.add(seg);
segs = segments.get(end);
if (segs == null) {
segs = newHashSet<RoadSegment>();
segments.put(end,segs);
}
segs.add(seg);
}
}
}
}
// Calculate the length of this road segment taking into account all of the
// intermediate geographic points.
privatestaticdoublegetRoadLength(GeographicPointstart, GeographicPointend,
List<GeographicPoint> path)
{
doubledist = 0.0;
GeographicPointcurr = start;
for (GeographicPointnext : path) {
dist += curr.distance(next);
curr = next;
}
dist += curr.distance(end);
returndist;
}
privatestaticList<GeographicPoint>
findPointsOnEdge(HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap,
RoadLineInfoinfo, Collection<GeographicPoint> nodes)
{
List<GeographicPoint> toReturn = newLinkedList<GeographicPoint>();
GeographicPointpt = info.point1;
GeographicPointend = info.point2;
List<LinkedList<RoadLineInfo>> nextInAndOut = pointMap.get(end);
LinkedList<RoadLineInfo> nextLines = nextInAndOut.get(0);
while (!nodes.contains(end)) {
toReturn.add(end);
RoadLineInfonextInfo = nextLines.get(0);
if (nextLines.size() == 2) {
if (nextInfo.point2.equals(pt)) {
nextInfo = nextLines.get(1);
}
}
elseif (nextLines.size() != 1) {
System.out.println("Something went wrong building edges");
}
pt = end;
end = nextInfo.point2;
nextInAndOut = pointMap.get(end);
nextLines = nextInAndOut.get(0);
}
toReturn.add(end);
returntoReturn;
}
// Find the other end of the road segment. Trace through the pointMap
// starting from the first point in this info until you get to the second.
privatestaticGeographicPoint
findEndOfEdge(HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap,
RoadLineInfoinfo, basicgraph.Graphgraph,
HashMap<GeographicPoint, Integer> reverseMap)
{
GeographicPointpt = info.point1;
GeographicPointend = info.point2;
IntegerendNum = reverseMap.get(end);
while (endNum==null) {
List<LinkedList<RoadLineInfo>> inAndOut = pointMap.get(end);
List<RoadLineInfo> nextLines = inAndOut.get(0);
RoadLineInfonextInfo = nextLines.get(0);
if (nextLines.size() == 2) {
if (nextInfo.point2.equals(pt)) {
nextInfo = nextLines.get(1);
}
}
elseif (nextLines.size() != 1) {
System.out.println("Something went wrong building edges");
}
pt = end;
end = nextInfo.point2;
endNum = reverseMap.get(end);
}
returnend;
}
// Find all the intersections. Intersections are either dead ends
// (1 road in and 1 road out, which are the reverse of each other)
// or intersections between two different roads, or where three
// or more segments of the same road meet.
privatestaticList<GeographicPoint>
findIntersections(HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap) {
// Now find the intersections. These are roads that do not have
// Exactly 1 or 2 roads coming in and out, where the roads in
// match the roads out.
List<GeographicPoint> intersections = newLinkedList<GeographicPoint>();
for (GeographicPointpt : pointMap.keySet()) {
List<LinkedList<RoadLineInfo>> roadsInAndOut = pointMap.get(pt);
LinkedList<RoadLineInfo> roadsOut = roadsInAndOut.get(0);
LinkedList<RoadLineInfo> roadsIn = roadsInAndOut.get(1);
booleanisNode = true;
if (roadsIn.size() == 1 && roadsOut.size() == 1) {
// If these are the reverse of each other, then this is
// and intersection (dead end)
if (!(roadsIn.get(0).point1.equals(roadsOut.get(0).point2) &&
roadsIn.get(0).point2.equals(roadsOut.get(0).point1))
&& roadsIn.get(0).roadName.equals(roadsOut.get(0).roadName)) {
isNode = false;
}
}
if (roadsIn.size() == 2 && roadsOut.size() == 2) {
// If all the road segments have the same name,
// And there are two pairs of reversed nodes, then
// this is not an intersection because the roads pass
// through.
Stringname = roadsIn.get(0).roadName;
booleansameName = true;
for (RoadLineInfoinfo : roadsIn) {
if (!info.roadName.equals(name)) {
sameName = false;
}
}
for (RoadLineInfoinfo : roadsOut) {
if (!info.roadName.equals(name)) {
sameName = false;
}
}
RoadLineInfoin1 = roadsIn.get(0);
RoadLineInfoin2 = roadsIn.get(1);
RoadLineInfoout1 = roadsOut.get(0);
RoadLineInfoout2 = roadsOut.get(1);
booleanpassThrough = false;
if ((in1.isReverse(out1) && in2.isReverse(out2)) ||
(in1.isReverse(out2) && in2.isReverse(out1))) {
passThrough = true;
}
if (sameName && passThrough) {
isNode = false;
}
}
if (isNode) {
intersections.add(pt);
}
}
returnintersections;
}
// Build the map from points to lists of lists of lines.
// The map returned is indexed by a GeographicPoint. The values
// are lists of length two where each entry in the list is a list.
// The first list stores the outgoing roads while the second
// stores the outgoing roads.
privatestaticHashMap<GeographicPoint, List<LinkedList<RoadLineInfo>>>
buildPointMapOneWay(Stringfilename)
{
BufferedReaderreader = null;
HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> pointMap =
newHashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>>();
try {
StringnextLine;
reader = newBufferedReader(newFileReader(filename));
// Read the lines out of the file and put them in a HashMap by points
while ((nextLine = reader.readLine()) != null) {
RoadLineInfoline = splitInputString(nextLine);
addToPointsMapOneWay(line, pointMap);
}
reader.close();
} catch (IOExceptione) {
System.err.println("Problem loading dictionary file: " + filename);
e.printStackTrace();
}
returnpointMap;
}
// Add the next line read from the file to the points map.
privatestaticvoid
addToPointsMapOneWay(RoadLineInfoline,
HashMap<GeographicPoint,List<LinkedList<RoadLineInfo>>> map)
{
List<LinkedList<RoadLineInfo>> pt1Infos = map.get(line.point1);
if (pt1Infos == null) {
pt1Infos = newArrayList<LinkedList<RoadLineInfo>>();
pt1Infos.add(newLinkedList<RoadLineInfo>());
pt1Infos.add(newLinkedList<RoadLineInfo>());
map.put(line.point1, pt1Infos);
}
List<RoadLineInfo> outgoing = pt1Infos.get(0);
outgoing.add(line);
List<LinkedList<RoadLineInfo>> pt2Infos = map.get(line.point2);
if (pt2Infos == null) {
pt2Infos = newArrayList<LinkedList<RoadLineInfo>>();
pt2Infos.add(newLinkedList<RoadLineInfo>());
pt2Infos.add(newLinkedList<RoadLineInfo>());
map.put(line.point2, pt2Infos);
}
List<RoadLineInfo> incoming = pt2Infos.get(1);
incoming.add(line);
}
// Split the input string into the line information
privatestaticRoadLineInfosplitInputString(Stringinput)
{
ArrayList<String> tokens = newArrayList<String>();
PatterntokSplitter = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"");
Matcherm = tokSplitter.matcher(input);
while (m.find()) {
if (m.group(1) != null) {
tokens.add(m.group(1));
}
else {
tokens.add(m.group());
}
}
doublelat1 = Double.parseDouble(tokens.get(0));
doublelon1 = Double.parseDouble(tokens.get(1));
doublelat2 = Double.parseDouble(tokens.get(2));
doublelon2 = Double.parseDouble(tokens.get(3));
GeographicPointp1 = newGeographicPoint(lat1, lon1);
GeographicPointp2 = newGeographicPoint(lat2, lon2);
returnnewRoadLineInfo(p1, p2, tokens.get(4), tokens.get(5));
}
publicstaticvoidmain(String[] args)
{
GraphLoader.createIntersectionsFile("data/maps/hollywood_small.map", "data/intersections/hollywood_small.intersections");
GraphLoader.createIntersectionsFile("data/maps/new_york.map", "data/intersections/new_york.intersections");
GraphLoader.createIntersectionsFile("data/maps/san_diego.map", "data/intersections/san_diego.intersections");
GraphLoader.createIntersectionsFile("data/maps/ucsd.map", "data/intersections/ucsd.intersections");
// To use this method to convert your custom map files to custom intersections files
// just change YOURFILE in the strings below to be the name of the file you saved.
// You can comment out the other method calls above to save time.
GraphLoader.createIntersectionsFile("data/maps/hillsboro.map",
"data/intersections/YOURFILE.intersections");
}
}
// A class to store information about the lines in the road files.
classRoadLineInfo
{
GeographicPointpoint1;
GeographicPointpoint2;
StringroadName;
StringroadType;
/** Create a new RoadLineInfo object to store information about the line
* read from the file
* @param p1 One of the points
* @param p2 The other point
* @param roadName The name of the road
* @param roadType The type of the road
*/
RoadLineInfo(GeographicPointp1, GeographicPointp2, StringroadName, StringroadType)
{
point1 = p1;
point2 = p2;
this.roadName = roadName;
this.roadType = roadType;
}
/** Get the other point from this roadLineInfo */
publicGeographicPointgetOtherPoint(GeographicPointpt)
{
if (pt == null) thrownewIllegalArgumentException();
if (pt.equals(point1)) {
returnpoint2;
}
elseif (pt.equals(point2)) {
returnpoint1;
}
elsethrownewIllegalArgumentException();
}
/** Two RoadLineInfo objects are considered equal if they have the same
* two points and the same roadName and roadType.
*/
publicbooleanequals(Objecto)
{
if (o == null || !(oinstanceofRoadLineInfo))
{
returnfalse;
}
RoadLineInfoinfo = (RoadLineInfo)o;
returninfo.point1.equals(this.point1) && info.point2.equals(this.point2) &&
info.roadType.equals(this.roadType) && info.roadName.equals(this.roadName);
}
/** Calculate the hashCode based on the hashCodes of the two points
* @return The hashcode for this object.
*/
publicinthashCode()
{
returnpoint1.hashCode() + point2.hashCode();
}
/** Returns whether these segments are part of the same road in terms of
* road name and road type.
* @param info The RoadLineInfo to compare against.
* @return true if these represent the same road, false otherwise.
*/
publicbooleansameRoad(RoadLineInfoinfo)
{
returninfo.roadName.equals(this.roadName) && info.roadType.equals(this.roadType);
}
/** Return a copy of this LineInfo in the other direction */
publicRoadLineInfogetReverseCopy()
{
returnnewRoadLineInfo(this.point2, this.point1, this.roadName, this.roadType);
}
/** Return true if this road is the same segment as other, but in reverse
* Otherwise return false.
*/
publicbooleanisReverse(RoadLineInfoother)
{
returnthis.point1.equals(other.point2) && this.point2.equals(other.point1) &&
this.roadName.equals(other.roadName) && this.roadType.equals(other.roadType);
}
/** Return the string representation of this LineInfo. */
publicStringtoString()
{
returnthis.point1 + " " + this.point2 + " " + this.roadName + " " + this.roadType;
}
}