Java Reference
In-Depth Information
Code 4.11
The log-file analyzer
public void analyzeHourlyData()
while (reader.hasNext()) {
LogEntry entry =;
int hour = entry.getHour();
* Print the hourly counts.
* These should have been set with a prior
* call to analyzeHourlyData.
public void printHourlyCounts()
System.out.println( "Hr: Count" );
for ( int hour = 0; hour < hourCounts.length; hour++) {
System.out.println(hour + ": " + hourCounts[hour]);
* Print the lines of data read by the LogfileReader
public void printData()
The analyzer currently uses only part of the data stored in a server's log line. It provides in-
formation that would allow us to determine which hours of the day, on average, tend to be the
busiest or quietest for the server. It does this by counting how many accesses were made in each
one-hour period over the duration covered by the log.
Exercise 4.61 Explore the weblog-analyzer project by creating a LogAnalyzer object and
calling its analyzeHourlyData method. Follow that with a call to its printHourlyCounts
method, which will print the results of the analysis. Which are the busiest times of the day?
Over the course of the next few sections, we shall examine how this class uses an array to
accomplish this task.
Search WWH ::

Custom Search