Kaynağa Gözat

minor display changes

Carolynn Vansant 6 yıl önce
ebeveyn
işleme
74dd6cef9f

+ 3
- 5
src/main/java/io/zipcoder/ItemParser.java Dosyayı Görüntüle

4
 import java.util.Arrays;
4
 import java.util.Arrays;
5
 import java.util.regex.Matcher;
5
 import java.util.regex.Matcher;
6
 import java.util.regex.Pattern;
6
 import java.util.regex.Pattern;
7
-import static java.util.regex.Pattern.CASE_INSENSITIVE;
8
-import static java.util.regex.Pattern.LITERAL;
9
 
7
 
10
 public class ItemParser {
8
 public class ItemParser {
11
 
9
 
64
     }
62
     }
65
 
63
 
66
     private ArrayList<String> splitStringWithRegexPattern(String stringPattern, String inputString){
64
     private ArrayList<String> splitStringWithRegexPattern(String stringPattern, String inputString){
67
-        return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
65
+        return new ArrayList<>(Arrays.asList(inputString.split(stringPattern)));
68
     }
66
     }
69
 
67
 
70
     public String normalizeRawData(String rawData){
68
     public String normalizeRawData(String rawData){
74
     }
72
     }
75
 
73
 
76
     public String convertWeirdCharactersToSemiColon(String rawData) {
74
     public String convertWeirdCharactersToSemiColon(String rawData) {
77
-        ArrayList<String> wierdCharacters = new ArrayList<>(Arrays.asList("^", "!", "*", "%"));
75
+        ArrayList<String> weirdCharacters = new ArrayList<>(Arrays.asList("^", "!", "*", "%"));
78
         Pattern pattern = Pattern.compile("@");
76
         Pattern pattern = Pattern.compile("@");
79
         Matcher matcher = pattern.matcher(rawData);
77
         Matcher matcher = pattern.matcher(rawData);
80
         String unWeird = matcher.replaceAll(";");
78
         String unWeird = matcher.replaceAll(";");
81
-        for (String character : wierdCharacters) {
79
+        for (String character : weirdCharacters) {
82
             matcher.reset(unWeird);
80
             matcher.reset(unWeird);
83
             matcher.usePattern(Pattern.compile(character, Pattern.LITERAL));
81
             matcher.usePattern(Pattern.compile(character, Pattern.LITERAL));
84
             unWeird = matcher.replaceAll(";");
82
             unWeird = matcher.replaceAll(";");

+ 11
- 7
src/main/java/io/zipcoder/ListCreation.java Dosyayı Görüntüle

19
     }
19
     }
20
 
20
 
21
     public String formattedGroceryListString(ArrayList<Item> groceryList) {
21
     public String formattedGroceryListString(ArrayList<Item> groceryList) {
22
-        LinkedHashMap<Double,Integer> priceOccur = new LinkedHashMap<>();
22
+        TreeMap<Double,Integer> priceOccur = new TreeMap<>();
23
         String list = "";
23
         String list = "";
24
         for (String key : keySet(groceryList)) {
24
         for (String key : keySet(groceryList)) {
25
             Pattern p = Pattern.compile(key);
25
             Pattern p = Pattern.compile(key);
60
         return keys;
60
         return keys;
61
     }
61
     }
62
 
62
 
63
-    public LinkedHashMap<Double, Integer> valueCount(ArrayList<Item> groceryList,String key) {
64
-        LinkedHashMap<Double, Integer> priceOccurrences = new LinkedHashMap<>();
63
+    public TreeMap<Double, Integer> valueCount(ArrayList<Item> groceryList,String key) {
64
+        TreeMap<Double, Integer> priceOccurrences = new TreeMap<>();
65
         for (Item item : groceryList) {
65
         for (Item item : groceryList) {
66
             Double price = item.getPrice();
66
             Double price = item.getPrice();
67
             if (key.equals(item.getName())) {
67
             if (key.equals(item.getName())) {
75
         return priceOccurrences;
75
         return priceOccurrences;
76
     }
76
     }
77
 
77
 
78
-    private String printValues(LinkedHashMap<Double, Integer> priceOccurrences) {
78
+    private String printValues(TreeMap<Double, Integer> priceOccurrences) {
79
         String valuesAndOccurrences = "";
79
         String valuesAndOccurrences = "";
80
-        for (Map.Entry<Double, Integer> entry : priceOccurrences.entrySet()) {
80
+
81
+        for (Map.Entry<Double, Integer> entry : priceOccurrences.descendingMap().entrySet()) {
81
             if(entry.getValue().equals(1)) {
82
             if(entry.getValue().equals(1)) {
82
                 valuesAndOccurrences += String.format("Price:   %1$.2f       seen: %2$d time \n", entry.getKey(), entry.getValue());
83
                 valuesAndOccurrences += String.format("Price:   %1$.2f       seen: %2$d time \n", entry.getKey(), entry.getValue());
83
             } else {
84
             } else {
84
                 valuesAndOccurrences += String.format("Price:   %1$.2f       seen: %2$d times\n", entry.getKey(), entry.getValue());
85
                 valuesAndOccurrences += String.format("Price:   %1$.2f       seen: %2$d times\n", entry.getKey(), entry.getValue());
85
             }
86
             }
86
-            valuesAndOccurrences += "-------------       -------------\n";
87
-
87
+            if(priceOccurrences.size()>1 && entry.getKey() != priceOccurrences.firstKey()) {
88
+                valuesAndOccurrences += "-------------       -------------\n";
89
+            } else if (priceOccurrences.size() == 1) {
90
+                valuesAndOccurrences += "-------------       -------------\n";
91
+            }
88
         }
92
         }
89
         valuesAndOccurrences += "\n";
93
         valuesAndOccurrences += "\n";
90
         return valuesAndOccurrences;
94
         return valuesAndOccurrences;

+ 1
- 1
src/test/java/io/zipcoder/ListCreationTest.java Dosyayı Görüntüle

73
         LinkedHashMap<Double,Integer> expected = new LinkedHashMap<>();
73
         LinkedHashMap<Double,Integer> expected = new LinkedHashMap<>();
74
         expected.put(3.23,2);
74
         expected.put(3.23,2);
75
         expected.put(2.00,1);
75
         expected.put(2.00,1);
76
-        LinkedHashMap<Double,Integer> actual = list.valueCount(itemObjects, "milk");
76
+        TreeMap<Double,Integer> actual = list.valueCount(itemObjects, "milk");
77
         Assert.assertEquals(expected, actual);
77
         Assert.assertEquals(expected, actual);
78
     }
78
     }
79
 
79