Due: 5/29, midnight by svn.
You must complete this assignment with your partner and should not discuss solutions with anyone but your partner and the course staff.
This assignment is due Tuesday at midnight.
Develop the visitor pattern for the binary trees data definition you developed in Lab 4.
Re-develop the methods of exercise 6-8 of Lab 4 as visitors.
Take a look at the code we wrote showing the perils of instanceof
and casts, which is on the Blog. Develop two corrections to
There is yet another approach to structural equality that we didn’t discuss in class, but which you have all the concepts needed to carry out. We can define equality by way of a visitor that computes whether the visited value is the same as some given value.
Develop the visitor pattern for the Drink data definition and design an implementation of DrinkVisitor<Boolean> that computes whether the visited drink is structurally equal to a given drink. You may find it useful to develop helper visitors.
Revisit your XML assignment and develop a same method that determines whether this XML is the same as some given XML. Two XML documents should be considered the same if they are structurally equal. You may use any approach you’d like, so long as it does not involve instanceof and casts (“safe casts” are OK).
Real XML considers the order of attributes to be irrelevant, so for example <img src="mom.jpg" alt="the best">...</img> is considered to equivalent to <img alt="the best" src="mom.jpg">...</img>, assuming the “...” are equivalent.
Modify your same method so that it ignores the order of attributes when considering whether two XML documents are the same.
Develop a method for XML that produces the string representation of an XML document, i.e., the toXMLString method should produce the string "<a href=\"google.com\">Search</a>" from the representation of <a href="google.com">Search</a>. Note that \" is how to write a double-quote inside of a string, so "I said \"Hello\"" is the string representation of the text I said "Hello".