Advertisement
4valeri

GUnit

Apr 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.LinkedHashMap;
  5. import java.util.Scanner;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class GUnit {
  10.     public static void main(String[] args) {
  11.         LinkedHashMap<String, LinkedHashMap<String, ArrayList<String>>> classNames = new LinkedHashMap<>();
  12.         Pattern pat = Pattern.compile("(\\w+) \\| (\\w+) \\| (\\w+)");
  13.  
  14.         String line;
  15.         Scanner scn = new Scanner(System.in);
  16.         String className;
  17.         String method;
  18.         String unitTest;
  19.         while (!(line = scn.nextLine()).equals("It's testing time!")) {
  20.             Matcher match = pat.matcher(line);
  21.             match.find();
  22.             className = match.group(1);
  23.             method = match.group(2);
  24.             unitTest = match.group(3);
  25.  
  26.             if (!classNames.containsKey(className)) {
  27.                 classNames.put(className, new LinkedHashMap<>());
  28.                 classNames.get(className).put("method", new ArrayList<>());
  29.                 classNames.get(className).put("unitTest", new ArrayList<>());
  30.             }
  31.             if (!classNames.containsKey(className)) {
  32.                 classNames.put(className, new LinkedHashMap<>());
  33.             }
  34.             classNames.get(className).get("method").add(method);
  35.             classNames.get(className).get("unitTest").add(unitTest);
  36.  
  37.  
  38.         }
  39.        
  40.        
  41.  
  42.         classNames.entrySet().stream()
  43.                 .sorted((e1,e2) -> {
  44.                     int total2 = (e2.getValue().get("method").size() + e2.getValue().get("unitTest").size());
  45.                     int total1 = (e1.getValue().get("method").size() + e1.getValue().get("unitTest").size());
  46.  
  47.                     if (total1 != total2) {
  48.                         return Integer.compare(total2, total1);
  49.                     }
  50.                     return e1.getKey().compareTo(e2.getKey());
  51.                 })
  52.                 .forEach(pair -> {
  53.                     System.out.println(pair.getKey() + ":");
  54.                     ArrayList<String> newMethod = pair.getValue().get("method");
  55.                     ArrayList<String> newUnit = pair.getValue().get("unitTest");
  56.                     printList2(newMethod);
  57.                     printList(newUnit);
  58.                 });
  59.     }
  60.  
  61.     private static void printList(ArrayList<String> list) {
  62.         list.stream().sorted((e1,e2) -> {
  63.             if (e1.length() != e2.length()) {
  64.                 return Integer.compare(e1.length(), e2.length());
  65.             }
  66.             return e1.compareTo(e2);
  67.         }).forEach(e1 -> {
  68.             System.out.println("####" + e1);
  69.         });
  70.     }
  71.  
  72.     private static void printList2(ArrayList<String> list) {
  73.         list.stream().sorted((e1,e2) -> {
  74.             if (e1.length() != e2.length()) {
  75.                 return Integer.compare(e1.length(), e2.length());
  76.             }
  77.             return e1.compareTo(e2);
  78.         }).forEach(e1 -> {
  79.             System.out.println("##" + e1);
  80.         });
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement