In the current version of the LineStorage class we have
the following data structure for storing lines:
lines_ of type
ArrayList holds all lines. The ArrayList
class implements all standard dynamic list operations, i.e., we can
add elements at the end of the list, we can insert elements in an
arbitrary position in the list, we can delete elements, etc. An
element stored in an ArrayList can be any Java
object since ArrayList holds instances of the
Object class. The Object class is the root
of the single rooted Java class hierarchy, i.e., any Java class is a
subclass of the Object class.
lines_ variable holds
objects of the ArrayList class. That means that each line
is stored within another object of ArrayList
class. Inside that second list words of a particular line are
stored. Words are stored as instances of the String
class.
You need to modify the data structure for storing lines in
LineStorage objects. The new data representation should
look as follows:
Line.
Line class stores a line into an object of the
ArrayList class. The name of this instance variable
should be words_. Words should be stored as instances of
the String class in the words_ object.
LineStorage class keeps lines in the same
lines_ object. However, this list is now filled with
instances of the Line class.
The following class diagram depicts the modifications you need to implement. Note, that the diagram shows only classes relevant for your current task. All other classes remain the same.
First, you need to implement an interactive version of the KWIC index system. That means the system won't read lines from a file but lines are inserted interactively by means of a simple command line user interface. Here is a transcript of a sample session:
Further, you need to modify how line shifting is performed. In the current version all lines are read at once, and line shifting is done on all lines at once after they are read. In the new version you need to perform line shifting on each line as it is read from the command line. The following sequence diagram depicts the new situation.
Thus in the new system KWIC object controls the command
line interface. After a command for adding a line has been issued, the
KWIC object invokes readLine method of the
Input object. The Input reads the line and
passes it to the CircularShifter object by invoking its
makeShifts method. After shifts have been made,
makeShifts and readLine methods return and
the KWIC object is again in charge, waiting for a new
command from the user.
Please, answer the following questions:
LineStorage class? What conclusion can you draw here? How
does the KWIC system implemented by means of object-oriented
architecture withstand design changes in data representation within
a particular module? Is this true for any other object-oriented
system?
Hints: