Browse Source

all tests passed

Lauren Green 6 years ago
parent
commit
42ad7c4bb0

+ 1
- 1
src/main/java/org/zipcoder/store/ListMap.java View File

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

+ 1
- 1
src/main/java/org/zipcoder/store/MyHashMap.java View File

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

+ 25
- 15
src/main/java/org/zipcoder/store/User.java View File

@@ -38,23 +38,33 @@ public class User {
38 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 68
     @Override
59 69
     public int hashCode() {
60 70
         return Objects.hash(id, name);