Java implementation
Listing 3-1 shows a test driver for a TimeSeries
class. The class is parameterized, the parameter being the object type of the event that is moving through time. In this program, that type is String
.
An array of six strings is defined at line 11. These will be the events to be loaded into the series
object that is instantiated at line 14. The loading is done by the load()
, defined at lines 27-31 and invoked at line 15.
The contents of the series are loaded at line 15. Then at lines 17-21, the six key-value pairs are printed. Finally, at lines 23-24, we use the direct access capability of the ArrayList
class to examine the series entry at index 3 (the fourth element). The output is shown in Figure 3-11.
Notice that the list's element type is TimeSeries.Entry
. That is a static
nested class, defined inside the TimeSeries
class, whose instances represent the key-value pairs...