Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.TreeMap;
- import java.util.TreeSet;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- @SuppressWarnings("ALL")
- public class _04LogParser {
- public static void main(String[] args) {
- Scanner get = new Scanner(System.in);
- String input = get.nextLine();
- String regex = "\\{\"Project\": \\[\"(.+)\"\\], \"Type\": \\[\"(.+)\"\\], \"Message\": \\[\"(.+)\"\\]\\}";
- Pattern myPattern = Pattern.compile(regex);
- TreeMap<String, TreeSet<ErrorMessage>> log = new TreeMap<>();
- // map of ^ Project and ^ erromsg(contains error type and message)
- while(!(input.equals("END"))){
- Matcher match = myPattern.matcher(input);
- while(match.find()){
- String projectName = match.group(1);
- String errorType = match.group(2);
- String errorMessage = match.group(3);
- if(!(log.containsKey(projectName))){
- log.put(projectName, new TreeSet<>());
- log.get(projectName).add(new ErrorMessage(errorType, errorMessage)); // <-- Issue here...
- }
- else{
- log.get(projectName).add(new ErrorMessage(errorType, errorMessage));
- }
- }
- input = get.nextLine();
- }
- }
- }
- class ErrorMessage{
- public void ErrorMessage(String type, String message){
- this.type = type;
- this.message = message;
- }
- private String type;
- private String message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement