Przeglądaj źródła

all tests passed

Lauren Green 6 lat temu
rodzic
commit
42ad7c4bb0

+ 1
- 1
src/main/java/org/zipcoder/store/ListMap.java Wyświetl plik

46
     public void put(User key, Cart value) {
46
     public void put(User key, Cart value) {
47
         if(get(key) != null) {
47
         if(get(key) != null) {
48
             for(Entry e : getEntries()) {
48
             for(Entry e : getEntries()) {
49
-                if(e.getKey() == key) {
49
+                if(e.getKey().equals(key)) {
50
                     e.setValue(value);
50
                     e.setValue(value);
51
                 }
51
                 }
52
             }
52
             }

+ 1
- 1
src/main/java/org/zipcoder/store/MyHashMap.java Wyświetl plik

95
     public Cart remove(User key) {
95
     public Cart remove(User key) {
96
         for (int i = 0; i < BUCKET_SIZE; i++) {
96
         for (int i = 0; i < BUCKET_SIZE; i++) {
97
             for (Entry e : getEntries()[i]) {
97
             for (Entry e : getEntries()[i]) {
98
-                if (e.getKey() == key) {
98
+                if (e.getKey().equals(key)) {
99
                     getEntries()[i].remove(e);
99
                     getEntries()[i].remove(e);
100
                     return e.getValue();
100
                     return e.getValue();
101
                 }
101
                 }

+ 25
- 15
src/main/java/org/zipcoder/store/User.java Wyświetl plik

38
         this.name = name;
38
         this.name = name;
39
     }
39
     }
40
 
40
 
41
-    public boolean equals(User otherUser) {
42
-
43
-    try {
44
-        if (this.getName().equalsIgnoreCase(otherUser.getName()) && this.getId() == otherUser.getId()) {
45
-            return true;
46
-        }
47
-    } catch (NullPointerException e) {
48
-
49
-        if (this.getName() == null && otherUser.getName() == null) {
50
-            return true;
51
-        } else {
52
-            return false;
53
-        }
54
-    }
55
-        return false;
41
+    @Override
42
+    public boolean equals(Object o) {
43
+        if (this == o) return true;
44
+        if (o == null || getClass() != o.getClass()) return false;
45
+        User user = (User) o;
46
+        return id == user.id &&
47
+                Objects.equals(name, user.name);
56
     }
48
     }
57
 
49
 
50
+    //    @Override
51
+//    public boolean equals(Object otherUser) {
52
+//
53
+//        try {
54
+//        if (this.getName().equalsIgnoreCase(otherUser.getName()) && this.getId() == otherUser.getId()) {
55
+//            return true;
56
+//        }
57
+//        } catch (NullPointerException e) {
58
+//
59
+//        if (this.getName() == null && otherUser.getName() == null) {
60
+//            return true;
61
+//        } else {
62
+//            return false;
63
+//        }
64
+//        }
65
+//        return false;
66
+//        }
67
+
58
     @Override
68
     @Override
59
     public int hashCode() {
69
     public int hashCode() {
60
         return Objects.hash(id, name);
70
         return Objects.hash(id, name);