CodeGym /Courses /Java Collections /Big task: Java log parser

Big task: Java log parser

Java Collections
Level 7 , Lesson 15
Available

"Hello, soldier!"

"Congratulations on upgrading your skills. We need guys who are prepared to do anything."

"I'm sure you still have many unfinished tasks. It's time to finish some of them!"

36
Task
Java Collections, level 7, lesson 15
Locked
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
Task
Java Collections, level 7, lesson 15
Locked
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
Task
Java Collections, level 7, lesson 15
Locked
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
Task
Java Collections, level 7, lesson 15
Locked
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
Task
Java Collections, level 7, lesson 15
Locked
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
Task
Java Collections, level 7, lesson 15
Locked
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
Task
Java Collections, level 7, lesson 15
Locked
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
Task
Java Collections, level 7, lesson 15
Locked
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.
Comments (4)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
matemate123 Level 50, Kraków, Poland
12 November 2023
One of my favorite projects so far. Learn how to reuse code and expand for new features. The Validator has a mercy here too.
Justin Smith Level 41, Greenfield, USA, United States
13 February 2023
I keep coming back to edit this as I progress through the task. This is one of my favorite big tasks so far. Really good project for learning to optimize your code efficiency. After part 1 I had almost 400 lines of code. It was super bloated. After part 2, I have... almost 400 lines of code, despite more than doubling the number of methods. In between (and I recommend you do this, too), I read up on how to use Java lambdas, and how they work with collection filtering. I think CodeGym doesn't go into lambdas because they were introduced with Java 8 and CG was developed for Java 7 originally. Anyway, as a learning experience I recommend just go through Part 1 and see how much redundant code you end up with, and then with part 2, scrap the whole thing and think strategically about how to compress the redundant code into only being called once. Ideally, you want a single method that handles all the filtering of the collection, and the methods that are required for the tasks just call that central method with appropriate parameters to get what they need. I suggest creating an Enum for the data type that you want to filter by or return. If you create a flexible query method by the end of Part 2, then Parts 3 & 4 become Easy tasks! This task is a great example of how I wish we had a place to discuss our own solutions, I'm really pleased with mine!
Senned Level 41, Azov, Russia
31 December 2019
First task: minus one day becouse parameters splited only by TAB(s.split("\t")). These are not in the conditions, but validator want it!(
Senned Level 41, Azov, Russia
4 January 2020
And attention in 7th task - dates "after" and "before" must not including!