fork download
  1. import java.util.*;
  2.  
  3. class ideone {
  4. public static void main(String[] args) {
  5. UserProgressModel model=new UserProgressModel("test@test.com");
  6. System.out.println(model.equals("test"));
  7.  
  8. UserProgressModel model2=new UserProgressModel("test@test.com");
  9. System.out.println(model2.equals("test@test.com"));
  10.  
  11. List<UserProgressModel> retUserProgress = new ArrayList<UserProgressModel>();
  12.  
  13. retUserProgress.add(model);
  14.  
  15. System.out.println(retUserProgress.contains(new UserProgressModel("test@test.com")));
  16.  
  17. }
  18. }
  19. class UserProgressModel {
  20.  
  21. private String email;
  22.  
  23. public UserProgressModel(String pEmail) {
  24. super();
  25.  
  26. this.email = pEmail;
  27. }
  28.  
  29. @Override
  30. public boolean equals(Object x) {
  31.  
  32. if (x != null && x instanceof UserProgressModel
  33. && ((UserProgressModel) x).email.equals(this.email) == true) {
  34.  
  35. return true;
  36. }
  37.  
  38. if (x != null && x instanceof String
  39. && x.equals(this.email) == true) {
  40.  
  41. return true;
  42. }
  43.  
  44. return false;
  45. }
  46.  
  47. @Override
  48. public int hashCode() {
  49. int hash = 7;
  50. hash = 17 * hash + (this.email != null ? this.email.hashCode() : 0);
  51. return hash;
  52. }
  53. }
  54.  
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
false
true
true