An index is a list of index entries, each of which identifies a keyword and an associated list of references. Each reference identifies a "place" where the keyword appears. In the index of a textbook, a reference typically indicates a page number. A text file could have an index in which each reference identifies the line number of an occurrence of a keyword. In an index maintained by a search engine such as Google, a reference might identify a particular web page and thus might take the form of a URL rather than an integer.
For the purposes of this assignment, we will keep things simple, so references are integers!
Provided are the following Java compilation units (interfaces and classes). The reader will notice that the names of the list-related entities are different from those that have been used in class and on web pages, as the word "Positional" has been omitted. The concepts are the same, however.
Students are strongly encouraged to complete the addReference() method so that the list of references remains in increasing order.
Students are free to add new private methods and even instance variables. One utility that could be used by both the addReference() and removeReference() methods is a method that searches within the entry's reference list for a specified number. It could return a new cursor positioned at the "right" place. Or, rather than returning a new cursor, it could have the effect of placing a "resident" cursor (stored in an instance variable) at that right place.
Notice that commands can be entered using either upper or lower case letters.
Welcome to the IndexEntryTester program. Enter a keyword: glorp > h Q : to quit H : to print this stuff P : to display/print the index entry I 35 : to add 35 into reference list R 27 : to remove 27 from reference list > P keyword: "glorp"; references: () > i 25 keyword: "glorp"; references: (25) > i 37 keyword: "glorp"; references: (25, 37) > i 11 keyword: "glorp"; references: (11, 25, 37) > I 20 keyword: "glorp"; references: (11, 20, 25, 37) |
> R 20 keyword: "glorp"; references: (11, 25, 37) > r 11 keyword: "glorp"; references: (25, 37) > r 37 keyword: "glorp"; references: (25) > r 25 keyword: "glorp"; references: () > i 15 keyword: "glorp"; references: (15) > i 24 keyword: "glorp"; references: (15, 24) > i 15 keyword: "glorp"; references: (15, 24) > q Goodbye. |
Make sure to complete the "header comments" by inserting your name where it belongs, by listing the names of any persons with whom you collaborated in developing your solution, and by describing any flaws/defects in your work of which you are aware.