Commit a3be8c0

mokha <mokha@cisco.com>
2019-04-28 20:06:51
implement equals
1 parent d4c7405
Changed files (2)
assignments
assignment1
src
main
java
ca
mokhan
assignment1
assignments/assignment1/src/main/java/ca/mokhan/assignment1/AddressBook.java
@@ -1,5 +1,7 @@
 package ca.mokhan.assignment1;
 
+import java.util.Objects;
+
 public class AddressBook implements Comparable<AddressBook>
 {
   private String businessPhone;
@@ -13,6 +15,21 @@ public class AddressBook implements Comparable<AddressBook>
   private String personalWebSite;
   private String skypeId;
 
+  public AddressBook() { }
+
+  public AddressBook(String businessPhone, String cellPhone, String facebookId, String firstName, String homeAddress, String homePhone, String lastName, String middleName, String personalWebSite, String skypeId) {
+    this.businessPhone = businessPhone;
+    this.cellPhone = cellPhone;
+    this.facebookId = facebookId;
+    this.firstName = firstName;
+    this.homeAddress = homeAddress;
+    this.homePhone = homePhone;
+    this.lastName = lastName;
+    this.middleName = middleName;
+    this.personalWebSite = personalWebSite;
+    this.skypeId = skypeId;
+  }
+
   public String getBusinessPhone() { return this.businessPhone; }
   public String getCellPhone() { return this.cellPhone; }
   public String getFacebookId() { return this.facebookId; }
@@ -46,4 +63,26 @@ public class AddressBook implements Comparable<AddressBook>
       this.middleName.compareTo(other.middleName) +
       this.lastName.compareTo(other.lastName);
   }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof AddressBook)) return false;
+    AddressBook that = (AddressBook) o;
+    return Objects.equals(businessPhone, that.businessPhone) &&
+            Objects.equals(cellPhone, that.cellPhone) &&
+            Objects.equals(facebookId, that.facebookId) &&
+            Objects.equals(firstName, that.firstName) &&
+            Objects.equals(homeAddress, that.homeAddress) &&
+            Objects.equals(homePhone, that.homePhone) &&
+            Objects.equals(lastName, that.lastName) &&
+            Objects.equals(middleName, that.middleName) &&
+            Objects.equals(personalWebSite, that.personalWebSite) &&
+            Objects.equals(skypeId, that.skypeId);
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(businessPhone, cellPhone, facebookId, firstName, homeAddress, homePhone, lastName, middleName, personalWebSite, skypeId);
+  }
 }
assignments/assignment1/.gitignore
@@ -1,1 +1,3 @@
 target
+.idea
+*.iml