Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. package GUnit;
  2.  
  3. import com.sun.source.tree.Tree;
  4.  
  5. import java.util.*;
  6. import java.util.regex.Pattern;
  7.  
  8. public class GUnit {
  9.  
  10. /*
  11. Class -> Method -> Unit tests
  12. */
  13. static Scanner scanner = new Scanner(System.in);
  14. static TreeMap<String, TreeMap<String, ArrayList<String>>> data = new TreeMap<>();
  15.  
  16. public static void main(String[] args) {
  17.  
  18. String line = scanner.nextLine();
  19.  
  20. while (!line.equals("It's testing time!")) {
  21.  
  22. String[] inputParams = line.split("[\\s|\\s]+");
  23. boolean isInputInRightFormat = checkInputParamsFormat(inputParams);
  24.  
  25. if (isInputInRightFormat) {
  26. // logic here
  27. String className = inputParams[0];
  28. String methodName = inputParams[1];
  29. String unitTest = inputParams[2];
  30.  
  31.  
  32. if(!data.containsKey(className)) {
  33. ArrayList<String> unitTests = new ArrayList<>();
  34. unitTests.add(unitTest);
  35.  
  36. TreeMap<String, ArrayList<String>> methods = new TreeMap<>();
  37. methods.put(methodName, unitTests);
  38.  
  39. data.put(className, methods);
  40. } else {
  41. if(!data.get(className).containsKey(methodName)) {
  42. data.get(className).put(methodName, new ArrayList<>()).add(unitTest);
  43. } else {
  44. data.get(className).get(methodName).add(unitTest);
  45. }
  46. }
  47.  
  48.  
  49.  
  50. // if(!data.containsKey(className)) {
  51. // data.put(className, new TreeMap<>());
  52. // }
  53. // if(!data.get(className).containsKey(methodName)) {
  54. // data.get(className).put(methodName, new ArrayList<>());
  55. // }
  56. //
  57. // data.get(className).get(methodName).add(unitTest);
  58.  
  59. }
  60.  
  61. line = scanner.nextLine();
  62. }
  63.  
  64. //System.out.println(data);
  65. /*
  66. Sort the dictionary by
  67. ---Classes dictionary
  68. 1. unitTests.count descending
  69. 2. methods.count ascending
  70. 3. classes ? methods alphabetically !!!!!
  71.  
  72. --- Methods dictionary
  73. 1. unitTests.count descending
  74. 2. alphabetically ? unitTests || methodName !!!!!
  75.  
  76. --- Unit tests ArrayList
  77. 1. length
  78. 2. alphabetically
  79. */
  80.  
  81. sortDictionary();
  82. printMap();
  83.  
  84.  
  85. }
  86.  
  87. private static void printMap() {
  88. }
  89.  
  90. private static void sortDictionary() {
  91. /*
  92. Map<String, Employee> sortedMap = map.entrySet()
  93. .stream()
  94. .sorted(Entry.comparingByValue(
  95. Comparator.comparing(Employee::getAge)
  96. .thenComparing(Employee::getSalary)))
  97. .collect(Collectors.toMap(Entry::getKey, Entry::getValue,
  98. (e1, e2) -> e1, LinkedHashMap::new));
  99. */
  100.  
  101. /*
  102. ---Classes dictionary
  103. 1. unitTests.count descending
  104. 2. methods.count ascending
  105. 3. classes ? methods alphabetically !!!!!
  106. */
  107.  
  108. TreeMap<String, TreeMap<String, ArrayList<String>>> sortedMap = data.entrySet()
  109. .stream()
  110. .sorted(Map.Entry.comparingByValue())
  111. }
  112.  
  113. private static boolean checkInputParamsFormat(String[] inputParams) {
  114.  
  115. for (String inputParam : inputParams) {
  116. // upper case letter atleast once, at least 2 characters, alphabet letters and digits
  117.  
  118. // upper case
  119. if (!Character.isUpperCase(inputParam.charAt(0))) {
  120. return false;
  121. }
  122.  
  123. if(inputParam.length() < 2) {
  124. return false;
  125. }
  126.  
  127. if (!Pattern.matches("[A-Za-z0-9]+", inputParam)) {
  128. return false;
  129. }
  130. }
  131.  
  132. return true;
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement