"Hej, soldat!"
"Tillykke med opgraderingen af dine færdigheder. Vi har brug for fyre, der er parate til at gøre alt."
"Jeg er sikker på, at du stadig har mange ufærdige opgaver. Det er tid til at afslutte nogle af dem!"
36
Opgave
Java Collections, niveau, lektie
Log parser (part 1)
Today we're going to write a log parser.
The log file has the following format:
ip username date event status
where:
ip is the IP address from which the user generated the event, user is the username (one or more words separated by spaces), date is the date of the event.
36
Opgave
Java Collections, niveau, lektie
Log parser (part 2)
Implement the UserQuery interface in the LogParser class:
2.1. The getAllUsers() method must return all users.
2.2. The getNumberOfUsers() method must return the number of unique users.
2.3. The getNumberOfUserEvents() method must return the number of events from a specific user.
36
Opgave
Java Collections, niveau, lektie
Log parser (part 3)
Implement the DateQuery interface in the LogParser class:
3.1. The getDatesForUserAndEvent() method must return the dates when a specific
user generated a specific event.
3.2. The getDatesWhenSomethingFailed() method must return the dates when
any event failed (FAILED status).
36
Opgave
Java Collections, niveau, lektie
Log parser (part 4)
Implement the EventQuery interface in the LogParser class:
4.1. The getNumberOfEvents() method must return the number of events in the specified period.
4.2. The getAllEvents() method must return all events in the specified period.
36
Opgave
Java Collections, niveau, lektie
Log parser (part 5)
As you noticed, there are a huge number of combinations of parameter to choose from for selecting
specific records from a log file. Cover them all with appropriate methods.
It's thankless work. So, we'll implement our own query language (QL).
36
Opgave
Java Collections, niveau, lektie
Log parser (part 6)
Let's add support for query parameters to our query language.
Examples of queries with parameters:
1) get ip for user = "Jack";
2) get user for event = "COMPLETE_TASK";
3) get event for date = "03.01.2014 03:45:23".
36
Opgave
Java Collections, niveau, lektie
Log parser (part 7)
Now give our query language support for an additional query parameter.
The additional parameter will be responsible for the range of dates we are interested in.
Example query: get ip for user = "Eduard Bentley" and date between
"11.12.2013 0:00:00" and "03.01.2014 23:59:59".
9
Opgave
Java Collections, niveau, lektie
Log parser (part 8)
You've implemented a log parser that reads from different files.
In addition to the parser, you also implemented your own query language. We need it in order to minimize
the number of methods. A line in our log file contained a total of 5 parameters plus one optional parameter.