Difference between revisions of "Spec 1.1 Errata"
Line 29: | Line 29: | ||
</blockquote> | </blockquote> | ||
Do not call System.out.println() to print out your output. Instead, create a new Document and append Elements to it as you process commands. You can print a Document to System.out using XmlUtility.print(). | Do not call System.out.println() to print out your output. Instead, create a new Document and append Elements to it as you process commands. You can print a Document to System.out using XmlUtility.print(). | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== [http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node24.html Drawing a spatial map using CanvasPlus] == | == [http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node24.html Drawing a spatial map using CanvasPlus] == |
Revision as of 01:11, 6 February 2017
Using the provided XML processing code to get a working parser[edit]
Node -> Element[edit]
In the DOM, every XML object implements the org.w3c.dom.Node interface. Nodes have a lot of useful methods, but the ones you care most about are getNodeName(), getNodeValue(), and getAttribute(). Suppose you had a Node object representing one of our command elements. You could determine which command it was with the following code:
Node command = ...; if (command.getNodeName().equals("createCity")) // createCity commandTo get the value of an attribute, you could use this code:
String name = command.getAttribute("name");
If you read the Java API, you'll see both Document and Element are subtypes of Node. A Node does not have the method getAttribute(). But Element does have a getAttribute() method.
Node Child List[edit]
To ignore comment nodes, you can even do an instanceof check of the command node to make sure it is of type Element.
instanceof checks can be costly. If there's an alternative, you should use it. That said, Node has a method called getNodeType().
Outputting XML Conventions[edit]
Printing to System.out[edit]
It is sufficient to merely spit these out to System.out (the standard output stream) as they are discovered when processing the commands. However, remember that the result must be a well-formed XML document and a well-formed XML document must have a single root element.
Do not call System.out.println() to print out your output. Instead, create a new Document and append Elements to it as you process commands. You can print a Document to System.out using XmlUtility.print().
Drawing a spatial map using CanvasPlus[edit]
Color class[edit]
It should be noted that all colors used in CanvasPlus refer to their java.awt.Color counterparts.
Input[edit]
spatialWidth and spatialHeight[edit]
The attributes are spatialWidth and spatialHeight, both Unrestricted Integers...
spatialWidth and spatialHeight will always be 2k by 2k. That way you can take advantage of bit operators.
List cities[edit]
listCities Prints all cities (vertices) currently present in the graph.
Graph here means data dictionary.
Nearest City tie[edit]
nearestCity Will return the name and location of the closest city to the specified point in space. To do this correctly, you may want to use the PriorityQueue-otherwise, you might not be fast enough.
If there is a distance tie, check the city names using java.lang.String.compareTo() (for a distance tie, the nearestCity name is less than the other city name).