Sfoglia il codice sorgente

minor display changes

Carolynn Vansant 6 anni fa
parent
commit
74dd6cef9f

+ 3
- 5
src/main/java/io/zipcoder/ItemParser.java Vedi File

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

+ 11
- 7
src/main/java/io/zipcoder/ListCreation.java Vedi File

@@ -19,7 +19,7 @@ public class ListCreation {
19 19
     }
20 20
 
21 21
     public String formattedGroceryListString(ArrayList<Item> groceryList) {
22
-        LinkedHashMap<Double,Integer> priceOccur = new LinkedHashMap<>();
22
+        TreeMap<Double,Integer> priceOccur = new TreeMap<>();
23 23
         String list = "";
24 24
         for (String key : keySet(groceryList)) {
25 25
             Pattern p = Pattern.compile(key);
@@ -60,8 +60,8 @@ public class ListCreation {
60 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 65
         for (Item item : groceryList) {
66 66
             Double price = item.getPrice();
67 67
             if (key.equals(item.getName())) {
@@ -75,16 +75,20 @@ public class ListCreation {
75 75
         return priceOccurrences;
76 76
     }
77 77
 
78
-    private String printValues(LinkedHashMap<Double, Integer> priceOccurrences) {
78
+    private String printValues(TreeMap<Double, Integer> priceOccurrences) {
79 79
         String valuesAndOccurrences = "";
80
-        for (Map.Entry<Double, Integer> entry : priceOccurrences.entrySet()) {
80
+
81
+        for (Map.Entry<Double, Integer> entry : priceOccurrences.descendingMap().entrySet()) {
81 82
             if(entry.getValue().equals(1)) {
82 83
                 valuesAndOccurrences += String.format("Price:   %1$.2f       seen: %2$d time \n", entry.getKey(), entry.getValue());
83 84
             } else {
84 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 93
         valuesAndOccurrences += "\n";
90 94
         return valuesAndOccurrences;

+ 1
- 1
src/test/java/io/zipcoder/ListCreationTest.java Vedi File

@@ -73,7 +73,7 @@ public class ListCreationTest {
73 73
         LinkedHashMap<Double,Integer> expected = new LinkedHashMap<>();
74 74
         expected.put(3.23,2);
75 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 77
         Assert.assertEquals(expected, actual);
78 78
     }
79 79