|
@@ -10,7 +10,7 @@ import java.util.stream.Collectors;
|
10
|
10
|
|
11
|
11
|
|
12
|
12
|
public class Main {
|
13
|
|
- public static int count;
|
|
13
|
+ private static int count;
|
14
|
14
|
Map<String, List<Double>> map = new HashMap<>();
|
15
|
15
|
|
16
|
16
|
private String readRawDataToString() throws Exception{
|
|
@@ -39,19 +39,37 @@ public class Main {
|
39
|
39
|
return list.size();
|
40
|
40
|
}
|
41
|
41
|
|
|
42
|
+ private String getCountPhrase(int num){
|
|
43
|
+ return num == 1 ? num + " time": num + " times";
|
|
44
|
+ }
|
|
45
|
+
|
42
|
46
|
public String writeOutput(){
|
43
|
47
|
StringBuilder sb = new StringBuilder();
|
|
48
|
+ String column1; String column2;
|
|
49
|
+
|
44
|
50
|
for (String s : map.keySet()){
|
45
|
|
- List<Double> l = map.get(s).stream().distinct().collect(Collectors.toList());
|
46
|
|
- sb.append(String.format("%14s %8s %14s\n","name: " + s, " ", "seen: " + map.get(s).size()));
|
|
51
|
+ List<Double> prices = map.get(s);
|
|
52
|
+ List<Double> uniquePrices = prices.stream().distinct().collect(Collectors.toList());
|
|
53
|
+
|
|
54
|
+ column1 = String.format("%-7s%7s", "Name: ", s);
|
|
55
|
+ column2 = String.format("%-7s%7s","Seen: ", getCountPhrase(prices.size()));
|
|
56
|
+
|
|
57
|
+ sb.append(String.format("%14s %8s %14s\n",column1, " ",column2));
|
47
|
58
|
sb.append(String.format("%14s %8s %14s\n","==============", " ", "=============="));
|
48
|
|
- for (Double d : l) {
|
49
|
|
- sb.append(String.format("%14s %8s %14s\n","Price: " + d, " ", "seen: " + getCount(map.get(s),d)));
|
|
59
|
+
|
|
60
|
+ for (Double d : uniquePrices) {
|
|
61
|
+ column1 = String.format("%-7s%7s", "Price: ", d);
|
|
62
|
+ column2 = String.format("%-7s%7s","Seen: ", getCountPhrase(getCount(prices,d)));
|
|
63
|
+
|
|
64
|
+ sb.append(String.format("%14s %8s %14s\n",column1, " ",column2));
|
50
|
65
|
sb.append(String.format("%14s %8s %14s\n","--------------", " ", "--------------"));
|
51
|
66
|
}
|
|
67
|
+ sb.append("\n");
|
52
|
68
|
}
|
53
|
69
|
|
54
|
|
- sb.append("\n").append(count);
|
|
70
|
+ column1 = "Errors";
|
|
71
|
+ column2 = String.format("%-7s%7s","Seen: ", getCountPhrase(count));
|
|
72
|
+ sb.append(String.format("%-14s %8s %14s",column1, " ",column2));
|
55
|
73
|
return sb.toString();
|
56
|
74
|
}
|
57
|
75
|
|