How to display ArrayList data every hour?


I want to show data in this format,

12-22-2011 11:00:00

[12-22-2011 11:13:39] Warning: Contact 'nagiosadmin' service notification command '/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: C:\ Drive Space\nHost: m-hussain.Musewerx2\nAddress:\nState: WARNING\n\nDate/Time: Thu Dec 22 11:13:08 EST 2011\n\nAdditional Info:\n\ncould not fetch information from server\n" | /bin/mail -s "** PROBLEM Service Alert: m-hussain.Musewerx2/C:\ Drive Space is WARNING **" [email protected]' timed out after 30 seconds

[12-22-2011 11:13:08] SERVICE NOTIFICATION: nagiosadmin;m-hussain.Musewerx2;C:\ Drive Space;WARNING;notify-service-by-email;could not fetch information from server

12-22-2011 10:00:00

[12-22-2011 10:02:19] SERVICE NOTIFICATION: nagiosadmin;arsalan.hussain;C:\ Drive Space;CRITICAL;notify-service-by-email;c:\ - total: 19.53 Gb - used: 19.17 Gb (98%) - free 0.36 Gb (2%)

[12-22-2011 10:00:29] Auto-save of retention data completed successfully.

my Array list such that each line of the above data is at unique index of array list how to campare data to show it hour wise,

ArrayList eventLog = new ArrayList();

Such that i have all data in array list i want to show data in this format how wouls i show data hourly wise in JSP

If the list is sorted you can do something like this (pure Java, translate to what you sue in your JSP)

String header = null;
List<String> lines = getLines();
for (String line: lines) {
    String currentTime = line.substring(1, 14);
    if (!currentTime.equals(header)) {
        header = currentTime;
        System.out.format("%0$s:00:00\n", header);

Starting with no header we iterate over all lines. The date and house are extracted from the current line. If they differ from the current header, then the header is changed to the current date and hour and printed. Then the line is printed.

If there are large gaps among the time stamps then no headers will be printed of those gaps.