Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package GUnit;
- import com.sun.source.tree.Tree;
- import java.util.*;
- import java.util.regex.Pattern;
- public class GUnit {
- /*
- Class -> Method -> Unit tests
- */
- static Scanner scanner = new Scanner(System.in);
- static TreeMap<String, TreeMap<String, ArrayList<String>>> data = new TreeMap<>();
- public static void main(String[] args) {
- String line = scanner.nextLine();
- while (!line.equals("It's testing time!")) {
- String[] inputParams = line.split("[\\s|\\s]+");
- boolean isInputInRightFormat = checkInputParamsFormat(inputParams);
- if (isInputInRightFormat) {
- // logic here
- String className = inputParams[0];
- String methodName = inputParams[1];
- String unitTest = inputParams[2];
- if(!data.containsKey(className)) {
- ArrayList<String> unitTests = new ArrayList<>();
- unitTests.add(unitTest);
- TreeMap<String, ArrayList<String>> methods = new TreeMap<>();
- methods.put(methodName, unitTests);
- data.put(className, methods);
- } else {
- if(!data.get(className).containsKey(methodName)) {
- data.get(className).put(methodName, new ArrayList<>()).add(unitTest);
- } else {
- data.get(className).get(methodName).add(unitTest);
- }
- }
- // if(!data.containsKey(className)) {
- // data.put(className, new TreeMap<>());
- // }
- // if(!data.get(className).containsKey(methodName)) {
- // data.get(className).put(methodName, new ArrayList<>());
- // }
- //
- // data.get(className).get(methodName).add(unitTest);
- }
- line = scanner.nextLine();
- }
- //System.out.println(data);
- /*
- Sort the dictionary by
- ---Classes dictionary
- 1. unitTests.count descending
- 2. methods.count ascending
- 3. classes ? methods alphabetically !!!!!
- --- Methods dictionary
- 1. unitTests.count descending
- 2. alphabetically ? unitTests || methodName !!!!!
- --- Unit tests ArrayList
- 1. length
- 2. alphabetically
- */
- sortDictionary();
- printMap();
- }
- private static void printMap() {
- }
- private static void sortDictionary() {
- /*
- Map<String, Employee> sortedMap = map.entrySet()
- .stream()
- .sorted(Entry.comparingByValue(
- Comparator.comparing(Employee::getAge)
- .thenComparing(Employee::getSalary)))
- .collect(Collectors.toMap(Entry::getKey, Entry::getValue,
- (e1, e2) -> e1, LinkedHashMap::new));
- */
- /*
- ---Classes dictionary
- 1. unitTests.count descending
- 2. methods.count ascending
- 3. classes ? methods alphabetically !!!!!
- */
- TreeMap<String, TreeMap<String, ArrayList<String>>> sortedMap = data.entrySet()
- .stream()
- .sorted(Map.Entry.comparingByValue())
- }
- private static boolean checkInputParamsFormat(String[] inputParams) {
- for (String inputParam : inputParams) {
- // upper case letter atleast once, at least 2 characters, alphabet letters and digits
- // upper case
- if (!Character.isUpperCase(inputParam.charAt(0))) {
- return false;
- }
- if(inputParam.length() < 2) {
- return false;
- }
- if (!Pattern.matches("[A-Za-z0-9]+", inputParam)) {
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement