Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- import java.util.TreeSet;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class GUnit {
- public static void main(String[] args) {
- List<Framework> data = new ArrayList<>();
- try (Scanner scanner = new Scanner(System.in);){
- String inputLine = scanner.nextLine();
- String pat = "^([A-Z][a-zA-Z0-9]+)\\s\\|\\s([A-Z][a-zA-Z0-9]+)\\s\\|\\s([A-Z][a-zA-Z0-9]+)$";
- while (true) {
- if (inputLine.equals("It's testing time!")) {
- break;
- }
- Pattern pattern = Pattern.compile(pat);
- Matcher match = pattern.matcher(inputLine);
- if (match.find()) {
- String className = match.group(1);
- String methodName = match.group(2);
- String testName = match.group(3);
- boolean isEmpty = checkForEmptyArray(data, className, methodName, testName);
- if (!isEmpty) {
- addObjectsToArray(data, className, methodName, testName);
- }
- }
- inputLine = scanner.nextLine();
- }
- data.sort((s1, s2) -> s1.getClassName().compareTo(s2.getClassName()));
- data.sort((s1, s2) -> Integer.compare(s1.countMetods , s2.countMetods));
- data.sort((s1, s2) -> Integer.compare(s2.countTests, s1.countTests));
- for (Framework framework : data) {
- System.out.println(framework + ":");
- framework.getMethods().entrySet()
- .stream()
- .sorted((s1,s2) -> Integer.compare(s2.getValue().size(),s1.getValue().size()))
- .forEach(pair -> {
- System.out.println("##" + pair.getKey());
- TreeSet<String> printList = pair.getValue();
- printList.stream().sorted((s1,s2) -> { return Integer.compare(s1.length(),s2.length()) == 0 ?
- s1.compareTo(s2): Integer.compare(s1.length(),s2.length());})
- .forEach(str -> System.out.println("####" + str));
- });;
- }
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- }
- public static void addObjectsToArray(List<Framework> data,
- String className, String methodName, String testName) {
- boolean isInside = false;
- for (Framework fr : data) {
- if (fr.getClassName().equals(className)) {
- isInside = true;
- fr.setMethods(methodName,testName);
- break;
- }
- }
- if (!isInside) {
- Framework framework = new Framework(className);
- framework.setMethods(methodName,testName);
- data.add(framework);
- }
- }
- public static boolean checkForEmptyArray(List<Framework> data,
- String className, String methodName, String testName) {
- if (data.isEmpty()) {
- Framework framework = new Framework(className);
- framework.setMethods(methodName,testName);
- data.add(framework);
- return true;
- }
- return false;
- }
- }
- class Framework implements Comparable<Framework> {
- private String className;
- private Map<String,TreeSet<String>> methods;
- public int countMetods;
- public int countTests;
- public Framework(String className) {
- super();
- this.className = className;
- this.methods = new TreeMap<String,TreeSet<String>>();
- }
- public String getClassName() {
- return className;
- }
- public void setClassName(String className) {
- this.className = className;
- }
- public Map<String, TreeSet<String>> getMethods() {
- return methods;
- }
- public void setMethods(String method, String test) {
- if (!methods.containsKey(method)) {
- methods.put(method, new TreeSet<String>());
- this.countMetods++;
- }
- int index = methods.get(method).size();
- if (method.contains(method)) {
- methods.get(method).add(test);
- if (methods.get(method).size() != index) {
- this.countTests++;
- }
- }
- }
- @Override
- public String toString() {
- return this.className;
- }
- public int compareTo(Framework framework) {
- Framework other = framework;
- return Integer.compare(this.countTests, other.countTests);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment