Advertisement
Guest User

Untitled

a guest
May 8th, 2016
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.TreeMap;
  3. import java.util.TreeSet;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. @SuppressWarnings("ALL")
  8. public class _04LogParser {
  9.     public static void main(String[] args) {
  10.         Scanner get = new Scanner(System.in);
  11.         String input = get.nextLine();
  12.  
  13.         String regex =  "\\{\"Project\": \\[\"(.+)\"\\], \"Type\": \\[\"(.+)\"\\], \"Message\": \\[\"(.+)\"\\]\\}";
  14.  
  15.         Pattern myPattern = Pattern.compile(regex);
  16.  
  17.         TreeMap<String, TreeSet<ErrorMessage>> log = new TreeMap<>();
  18.         // map of ^ Project and ^ erromsg(contains error type and message)
  19.         while(!(input.equals("END"))){
  20.  
  21.             Matcher match = myPattern.matcher(input);
  22.             while(match.find()){
  23.                 String projectName = match.group(1);
  24.                 String errorType = match.group(2);
  25.                 String errorMessage = match.group(3);
  26.  
  27.                 if(!(log.containsKey(projectName))){
  28.                     log.put(projectName, new TreeSet<>());
  29.                     log.get(projectName).add(new ErrorMessage(errorType, errorMessage)); // <-- Issue here...
  30.                 }
  31.  
  32.                 else{
  33.                     log.get(projectName).add(new ErrorMessage(errorType, errorMessage));
  34.                 }
  35.  
  36.             }
  37.  
  38.  
  39.             input = get.nextLine();
  40.         }
  41.  
  42.  
  43.     }
  44. }
  45.  
  46.  
  47. class ErrorMessage{
  48.     public void ErrorMessage(String type, String message){
  49.         this.type = type;
  50.         this.message = message;
  51.     }
  52.  
  53.     private String type;
  54.     private String message;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement