Time range

I have a log file which contains entries like

8-25-2006 11:43:08, orange

8-25-2006 13:50:14, apple

8-25-2006 13:55:14, orange

I want to classify what time this log entry is made, so what I want is to have an array of 24 that would contain the number of messages logged within that range such that

arr[0] = 0; // 0:00:01 - 1:00:00

arr[1] = 0; // 1:00:01 - 2:00:00

:

:

:

arr[10] = 1; // 11:00:01 - 12:00:00

arr[11] = 0; // 12:00:01 - 13:00:00

arr[12] = 2; // 13:00:01 - 14:00:00

:

:

:

arr[23] = 0; // 23:00:01 - 0:00:00

Can anyone suggest what is the best way to go around this? Thank you in advance!

[707 byte] By [mpanga] at [2007-10-3 3:32:55]
# 1
String.substring(), Integer.parseIntOr, in OO:create a LogEntry class with a queriable timestamp
CeciNEstPasUnProgrammeura at 2007-7-14 21:27:13 > top of Java-index,Java Essentials,Java Programming...
# 2
what does it mean by queriable timestamp?
mpanga at 2007-7-14 21:27:13 > top of Java-index,Java Essentials,Java Programming...
# 3

correction pls

arr[0] = 0; // 0:00:01 - 1:00:00

arr[1] = 0; // 1:00:01 - 2:00:00

:

:

:

arr[10] = 1; // 10:00:01-11:00:00 instead of 11:00:01 - 12:00:00

and so on

Logic

Get hour,minute and second value of time field from log file into

int hour,min,sec resp;

//so hour =0 for any value between 0:00:01 - 1:00:00

// hour =1 for any value between 1:00:01 - 2:00:00

arr[hour]++;

// will increment respective counter

Critical problem

Hour value bet 0:00:00 to 0:59:59 hour will be 0

but for 1:00:00 hour=1

hence for 1:00:00 counter arr[1] will be incremented

to avoid this have a check condition

if min ==0 and sec ==0 // hour =1 for 1:00:00

hour--; // 1:00:00 should be included to arr[0]

fair code

hour=....;

sec=..;

min=..;

if (sec==0&& min==0)

hour--;

arr[hour]++;

arr[hour]++;

vipuluckya at 2007-7-14 21:27:13 > top of Java-index,Java Essentials,Java Programming...
# 4
> what does it mean by queriable timestamp?An internally stored time stamp, like a Date object (see SimpleDateFormat) and getters that can tell you the hour number of the logged element (see Calendar).
CeciNEstPasUnProgrammeura at 2007-7-14 21:27:13 > top of Java-index,Java Essentials,Java Programming...
# 5

> Logic

> Get hour,minute and second value of time field from

> log file into

> int hour,min,sec resp;

Logic: get the hour from the log file and ignore minutes and seconds completely. Hour will be 1..24 or 0..23, adjust as required.

You will have an error of 1 second every hour which I am sure you can cope with.

ejpa at 2007-7-14 21:27:13 > top of Java-index,Java Essentials,Java Programming...