From 5ce9f0f6b9530db5e733b33932b7528296e1fbfc Mon Sep 17 00:00:00 2001 From: Victor Zamanian Date: Fri, 17 Oct 2008 16:10:58 +0200 Subject: [PATCH] Fixed some javadoc and some output. --- src/GraphNode.java | 2 +- src/MySearcher.java | 39 +++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/GraphNode.java b/src/GraphNode.java index dff5b79..0e398b6 100644 --- a/src/GraphNode.java +++ b/src/GraphNode.java @@ -81,7 +81,7 @@ public class GraphNode implements Comparable { /** * Inspects all the neighbours (nodes) of this node. * - * @return A Vector with all neighbours. + * @return An Enumeration of all neighbours of this node.. */ public Enumeration getNeighbours() { return neighbours.keys(); diff --git a/src/MySearcher.java b/src/MySearcher.java index a4dc392..de1924d 100644 --- a/src/MySearcher.java +++ b/src/MySearcher.java @@ -3,12 +3,12 @@ import java.io.IOException; import java.util.List; import java.util.LinkedList; import java.util.PriorityQueue; -import java.util.Hashtable; import java.util.Enumeration; import org.jdom.*; /** - * Beskrivning av klassen. + * Denna klass implementerar olika sökalgoritmer för att hitta vägar + * mellan två platser på en karta. */ public class MySearcher extends MapSearcher { private Graph map; @@ -21,10 +21,9 @@ public class MySearcher extends MapSearcher { } /** - * Specificerar kartan. + * Specificerar kartan utifrån en fil i XML-format. * * @param map Den XML-fil som representerar kartan. - * */ public void setMap(File mapFile) { Document doc; @@ -64,11 +63,12 @@ public class MySearcher extends MapSearcher { System.exit(1); } catch (JDOMException e) { - System.err.println ("File is not in valid XML format?"); + System.err.println (e.getMessage()); System.exit(1); } catch (NumberFormatException e) { - System.err.println ("Coordinates cannot be parsed."); + System.err.println ("Coordinates cannot be parsed. Check XML-file for errors."); + System.exit1(1); } } @@ -77,6 +77,7 @@ public class MySearcher extends MapSearcher { * * @param from Den plats sökningen börjar från. * @param to Den plats sökningen avslutas på. + * @return En sträng som representerar vägen från start till mål. */ public String greedySearch (String from, String to) { String pathToGoal = "", @@ -104,9 +105,8 @@ public class MySearcher extends MapSearcher { n = n.getParent(); } pathToGoal = n.getName() + ", " + pathToGoal; // Beginning - - return "\nAll visited nodes:\n" + expandedNodes + "\n\n" - + "Path to goal:\n" + pathToGoal + "\n"; + System.out.println("\nAll visited nodes:\n" + expandedNodes + "\n\n"); + return "Path to goal:\n" + pathToGoal + "\n"; } // 5. Otherwise add the children of n to N, GraphNode neighbour; @@ -122,7 +122,7 @@ public class MySearcher extends MapSearcher { } } // 2. ... exit and signal failure - return "Goal not found\n"; + return "Goal not found!\n"; } /** @@ -159,9 +159,8 @@ public class MySearcher extends MapSearcher { n = n.getParent(); } pathToGoal = n.getName() + ", " + pathToGoal; // Beginning - - return "\nAll visited nodes:\n" + expandedNodes + "\n\n" - + "Path to goal:\n" + pathToGoal + "\n"; + System.out.println("\nAll visited nodes:\n" + expandedNodes + "\n\n"); + return "Path to goal:\n" + pathToGoal + "\n"; } // 5. Otherwise add the children of n to N, GraphNode neighbour; @@ -182,7 +181,7 @@ public class MySearcher extends MapSearcher { } System.out.println(); // 2. ... exit and signal failure - return null; + return "Goal not found!\n"; } /** @@ -220,8 +219,8 @@ public class MySearcher extends MapSearcher { n = n.getParent(); } pathToGoal = n.getName() + ", " + pathToGoal; // Beginning - return "\nAll visited nodes:\n" + expandedNodes + "\n\n" - + "Path to goal:\n" + pathToGoal + "\n"; + System.out.println("\nAll visited nodes:\n" + expandedNodes + "\n\n"); + return "Path to goal:\n" + pathToGoal + "\n"; } // * Otherwise push all the (so-far-unexamined) successors // * (the direct child nodes) of this node into the end of @@ -237,7 +236,7 @@ public class MySearcher extends MapSearcher { } expandedNodes += n.getName() + ", "; } - return "Goal not found!"; + return "Goal not found!\n"; } /** @@ -269,8 +268,8 @@ public class MySearcher extends MapSearcher { n = n.getParent(); } pathToGoal = n.getName() + ", " + pathToGoal; // Beginning - return "\nAll visited nodes:\n" + expandedNodes + "\n\n" - + "Path to goal:\n" + pathToGoal + "\n"; + System.out.println("\nAll visited nodes:\n" + expandedNodes + "\n\n"); + return "Path to goal:\n" + pathToGoal + "\n"; } // * Otherwise push all the unvisited connecting nodes of n else { @@ -285,7 +284,7 @@ public class MySearcher extends MapSearcher { } expandedNodes += n.getName() + ", "; } - return "\nGoal not found!"; + return "Goal not found!\n"; } public String toString() { -- 2.11.4.GIT