Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- public class LogSearcher {
- public Collection<String> search(Collection<String> logLines, LocalTime startDate, LocalTime endDate) {
- Collection<String> res = new ArrayList<String>();
- String[] temp;
- DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
- for(String logLine : logLines) {
- temp = logLine.split("\t");
- System.out.println(temp[0]);
- try {
- LocalTime time = LocalTime.parse(temp[0], formatter);
- if((time.isAfter(startDate) && time.isBefore(endDate))) {
- res.add(logLine);
- } else if(time.equals(startDate)) {
- res.add(logLine);
- }
- if(time.isAfter(endDate)) {
- break;
- }
- } catch (Exception e) {
- return new ArrayList<String>();
- }
- }
- return res;
- }
- public static void main(String[] args) throws IOException{
- Scanner in = new Scanner(System.in);
- final String fileName = System.getenv("OUTPUT_PATH");
- BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
- DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
- LocalTime startDate = LocalTime.parse(in.nextLine(), formatter);
- LocalTime endDate = LocalTime.parse(in.nextLine(), formatter);
- final int numberOfLogLines = Integer.parseInt(in.nextLine());
- Collection<String> logLines = new ArrayList<String>();
- for (int i = 0; i < numberOfLogLines; i++) {
- logLines.add(in.nextLine());
- }
- in.close();
- Collection<String> res = new LogSearcher().search(logLines, startDate, endDate);
- for (String logLine : res) {
- bw.write(logLine);
- bw.newLine();
- }
- bw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement