File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
app/src/main/java/com/rxjava2/android/samples Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -27,4 +27,22 @@ public String toString() {
27
27
", isFollowing=" + isFollowing +
28
28
'}' ;
29
29
}
30
+
31
+ @ Override
32
+ public int hashCode () {
33
+ return (int ) id + firstname .hashCode () + lastname .hashCode ();
34
+ }
35
+
36
+ @ Override
37
+ public boolean equals (Object obj ) {
38
+ if (obj instanceof User ) {
39
+ User user = (User ) obj ;
40
+
41
+ return this .id == user .id
42
+ && this .firstname .equals (user .firstname )
43
+ && this .lastname .equals (user .lastname );
44
+ }
45
+
46
+ return false ;
47
+ }
30
48
}
Original file line number Diff line number Diff line change @@ -152,13 +152,13 @@ public void onComplete() {
152
152
153
153
private List <User > filterUserWhoLovesBoth (List <User > cricketFans , List <User > footballFans ) {
154
154
List <User > userWhoLovesBoth = new ArrayList <>();
155
- for (User cricketFan : cricketFans ) {
156
- for (User footballFan : footballFans ) {
157
- if (cricketFan .id == footballFan .id ) {
158
- userWhoLovesBoth .add (cricketFan );
159
- }
155
+
156
+ for (User footballFan : footballFans ) {
157
+ if (cricketFans .contains (footballFan )) {
158
+ userWhoLovesBoth .add (footballFan );
160
159
}
161
160
}
161
+
162
162
return userWhoLovesBoth ;
163
163
}
164
164
You can’t perform that action at this time.
0 commit comments