Advertisement
ivanov_ivan

GUnit

May 5th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 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. import java.util.stream.Collectors;
  7.  
  8. public class GUnit {
  9.     public static void main(String[] args) {
  10.         Scanner sc = new Scanner(System.in);
  11.  
  12.         //TreeMap<String, TreeSet<String>> classAndMethod = new TreeMap<>();
  13.         TreeMap<String, TreeMap<String, TreeSet<String>>> methodAndTest = new TreeMap<>();
  14.  
  15.         Pattern pat = Pattern.compile("^(?<class>[A-Z][A-Za-z0-9]{1,}){1,}\\s\\|\\s(?<method>[A-Z][A-Za-z0-9]{1,}){1,}\\s\\|\\s(?<unit>[A-Z][A-Za-z0-9]{1,}){1,}$");
  16.  
  17.         String input = sc.nextLine();
  18.  
  19.         while (!input.equals("It's testing time!")) {
  20.             Matcher match = pat.matcher(input);
  21.             while (match.find()) {
  22.                 if (!methodAndTest.containsKey(match.group("class"))) {
  23.                     TreeMap<String, TreeSet<String>> tmpMap = new TreeMap<>();
  24.                     TreeSet<String> tmpSet = new TreeSet<>();
  25.                     tmpSet.add(match.group("unit"));
  26.                     tmpMap.put(match.group("method"), tmpSet);
  27.                     methodAndTest.put(match.group("class"), tmpMap);
  28.                 } else {
  29.                     TreeMap<String, TreeSet<String>> tmpMap = new TreeMap<>(methodAndTest.get(match.group("class")));
  30.                     TreeSet<String> tmpSet = new TreeSet<>();
  31.                     if (!tmpMap.containsKey(match.group("method"))) {
  32.                         tmpSet.add(match.group("unit"));
  33.                         tmpMap.put(match.group("method"), tmpSet);
  34.                     } else {
  35.                         tmpSet = new TreeSet<>(tmpMap.get(match.group("method")));
  36.                         tmpSet.add(match.group("unit"));
  37.                         tmpMap.put(match.group("method"), tmpSet);
  38.                     }
  39.                     methodAndTest.put(match.group("class"), tmpMap);
  40.                 }
  41.             }
  42.             input = sc.nextLine();
  43.         }
  44.  
  45.         methodAndTest.entrySet().stream().sorted((e1, e2) -> {
  46.             /// sorting the outer map by most inner values
  47.             int amountOfTest1 = e1.getValue().values().stream().collect(Collectors.summingInt(value -> value.size()));
  48.             int amountOfTest2 = e2.getValue().values().stream().collect(Collectors.summingInt(value -> value.size()));
  49.  
  50.             if (amountOfTest1 == amountOfTest2) {
  51.                 // sorting by methods // inner map keys //
  52.                 int innerMapKeys1 = e1.getValue().size();
  53.                 int innerMapKeys2 = e2.getValue().size();
  54.  
  55.                 return Integer.compare(innerMapKeys1, innerMapKeys2);
  56.  
  57.             } else {
  58.                 //sorting by count of tests // inner values //
  59.                 return Integer.compare(amountOfTest2, amountOfTest1);// Count of test
  60.             }
  61.         }).forEach(classesAndMethods -> {
  62.             System.out.println(classesAndMethods.getKey() + ":");
  63.  
  64.             // sorting methods by count of the tests
  65.             classesAndMethods.getValue().entrySet().stream().sorted((a1, a2) -> {
  66.                 int testCount1 = a1.getValue().size();
  67.                 int testCount2 = a2.getValue().size();
  68.                 return Integer.compare(testCount2, testCount1);
  69.             }).forEach(methodAndTests -> {
  70.                 System.out.printf("##%s\n", methodAndTests.getKey());
  71.                 //sorting the test by there length
  72.                 methodAndTests.getValue().stream().sorted((a, b2) -> Integer.compare(a.length(), b2.length())).forEach(tests -> {
  73.                     System.out.printf("####%s\n", tests);
  74.                 });
  75.             });
  76.         });
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement