Chad 6 vuotta sitten
vanhempi
commit
e2f78433d3

+ 14
- 0
src/main/java/org/zipcoder/store/Cart.java Näytä tiedosto

@@ -12,4 +12,18 @@ public class Cart {
12 12
     public long getId(){
13 13
         return this.id;
14 14
     }
15
+
16
+    @Override
17
+    public boolean equals(Object o) {
18
+        if (this == o) return true;
19
+        if (o == null || getClass() != o.getClass()) return false;
20
+        Cart cart = (Cart) o;
21
+        return id == cart.id;
22
+    }
23
+
24
+    @Override
25
+    public int hashCode() {
26
+
27
+        return Objects.hash(id);
28
+    }
15 29
 }

+ 5
- 2
src/main/java/org/zipcoder/store/ListMap.java Näytä tiedosto

@@ -9,17 +9,20 @@ public class ListMap implements MyMap {
9 9
 
10 10
     @Override
11 11
     public int size() {
12
-        return -1;
12
+        return entries.size();
13 13
     }
14 14
 
15 15
     @Override
16 16
     public boolean isEmptry() {
17
-        return false;
17
+        return entries.size()==0;
18 18
     }
19 19
 
20 20
     @Override
21 21
     public Cart get(User key) {
22 22
         // find the cart associate with the key
23
+        for(int i=0; i<entries.size(); i++){
24
+
25
+        }
23 26
         return null;
24 27
     }
25 28
 

+ 19
- 0
src/main/java/org/zipcoder/store/User.java Näytä tiedosto

@@ -37,4 +37,23 @@ public class User {
37 37
     public void setName(String name) {
38 38
         this.name = name;
39 39
     }
40
+
41
+
42
+    public boolean equals(Object obj) {
43
+        boolean same = false;
44
+        User user = (User) obj;
45
+        if(user.getName()== null){
46
+            if(user.getId() == this.id){
47
+                same = true;
48
+            }
49
+        }else if((user.getId() == this.id) && (user.getName().equalsIgnoreCase(this.name))){
50
+            same = true;
51
+        }
52
+        return same;
53
+    }
54
+
55
+    @Override
56
+    public int hashCode() {
57
+        return Objects.hash(id, name);
58
+    }
40 59
 }