|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Path
A path is a sequence of nodes describing how to get from one node to
another in a graph.
A node is represented by its name (a String
).
A node can not occur more than once in a single path.
The path is initialized by a call to computePath() after which the
relevant information can be retrieved using the methods getPath() and
getPathLength().
All implementations of a Path must support two constructors both taking two arguments; one takes the name of a stop file and the name of a line file, and the other takes two lists with the stops and lines (i.e List<BStop> and List<BLineTable>).
A class implementing Path could be used as follows:
Lab4File lab4file = new Lab4File(); List stops = lab4file.readStops("stops-gbg.txt"); List lines = lab4file.readLines("lines-gbg.txt"); Path p = new MyPath(stops, lines); p.computePath("Chalmers","Angered"); System.out.println("Distance: " + p.getPathLength()); p.computePath("Chalmers","GuldHeden"); System.out.println("Distance: " + p.getPathLength());
Method Summary | |
---|---|
void |
computePath(java.lang.String from,
java.lang.String to)
Computes the path from from to to. |
java.util.Iterator<java.lang.String> |
getPath()
Return an iterator over (the names of) the nodes in the path. |
int |
getPathLength()
Returns the length of the computed path, that is, the sum of the weights of each arc on the path. |
Method Detail |
---|
void computePath(java.lang.String from, java.lang.String to)
java.util.Iterator<java.lang.String> getPath()
If a path has been found the first node in the iterator is the argument from passed to computePath and the last node is to.
If no path was found or if no call to computePath has been made the iterator is empty.
int getPathLength()
If no path was found the return value is an arbitrary integer. It is appropriate but not required to return a special value such as -1 in this case.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |