Do exercise 2.7 on page 47.
Do exercise 2.9 on page 47.
Exercise 2.x2: Use Java generics to write an Index
class that can be used to keep an index of what web pages contain
particular words. Your class should support two methods. The
put method should take a String and a
URL and record that the given String appears
in the web page specified by the URL. The
get method should take a String and return a
Set of URLs that were recorded as containing
that String. The program IndexTest.java linked to this
homework is a test program that would use your Index
class. If you compile this file and the file you write, you should
then be able to give the command
java IndexTest Hailperin Java homework type technology
and get back the results
Hits for Hailperin: http://www.gustavus.edu/+max/courses/S2006/MCS-287/syllabus.html http://www.gustavus.edu/+max/ Hits for Java: http://www.gustavus.edu/+max/courses/S2006/MCS-287/syllabus.html http://java.sun.com/ Hits for homework: http://www.gustavus.edu/+max/courses/S2006/MCS-287/syllabus.html Hits for type: http://www.gustavus.edu/+max/courses/S2006/MCS-287/syllabus.html http://java.sun.com/ Hits for technology: http://java.sun.com/ http://www.gustavus.edu/+max/
Here are some details:
In addition to the class java.net.URL, you should
use the interfaces java.util.Set and
java.util.Map and the classes
java.util.HashSet and java.util.HashMap.
Your Index should find matches independent of lower case versus
upper case. For example, in the test shown above, the two web pages
listed for type might actually have contained
type, Type, or TYPE. The
simplest way to achieve this is to convert the Strings
that the put and get methods receive into
lower case.
When your get method hands back a Set
of URLs, it would be good to prevent the caller from
modifying that Set. You can achieve this using a method defined in java.util.Collections.