Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class GUnit {
- public static void main(String[] args) {
- LinkedHashMap<String, LinkedHashMap<String, ArrayList<String>>> classNames = new LinkedHashMap<>();
- Pattern pat = Pattern.compile("(\\w+) \\| (\\w+) \\| (\\w+)");
- String line;
- Scanner scn = new Scanner(System.in);
- String className;
- String method;
- String unitTest;
- while (!(line = scn.nextLine()).equals("It's testing time!")) {
- Matcher match = pat.matcher(line);
- match.find();
- className = match.group(1);
- method = match.group(2);
- unitTest = match.group(3);
- if (!classNames.containsKey(className)) {
- classNames.put(className, new LinkedHashMap<>());
- classNames.get(className).put("method", new ArrayList<>());
- classNames.get(className).put("unitTest", new ArrayList<>());
- }
- if (!classNames.containsKey(className)) {
- classNames.put(className, new LinkedHashMap<>());
- }
- classNames.get(className).get("method").add(method);
- classNames.get(className).get("unitTest").add(unitTest);
- }
- classNames.entrySet().stream()
- .sorted((e1,e2) -> {
- int total2 = (e2.getValue().get("method").size() + e2.getValue().get("unitTest").size());
- int total1 = (e1.getValue().get("method").size() + e1.getValue().get("unitTest").size());
- if (total1 != total2) {
- return Integer.compare(total2, total1);
- }
- return e1.getKey().compareTo(e2.getKey());
- })
- .forEach(pair -> {
- System.out.println(pair.getKey() + ":");
- ArrayList<String> newMethod = pair.getValue().get("method");
- ArrayList<String> newUnit = pair.getValue().get("unitTest");
- printList2(newMethod);
- printList(newUnit);
- });
- }
- private static void printList(ArrayList<String> list) {
- list.stream().sorted((e1,e2) -> {
- if (e1.length() != e2.length()) {
- return Integer.compare(e1.length(), e2.length());
- }
- return e1.compareTo(e2);
- }).forEach(e1 -> {
- System.out.println("####" + e1);
- });
- }
- private static void printList2(ArrayList<String> list) {
- list.stream().sorted((e1,e2) -> {
- if (e1.length() != e2.length()) {
- return Integer.compare(e1.length(), e2.length());
- }
- return e1.compareTo(e2);
- }).forEach(e1 -> {
- System.out.println("##" + e1);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement