Last active
November 30, 2017 10:18
-
-
Save malys/836e8c8485931991731b to your computer and use it in GitHub Desktop.
[Guava Tips] #java #guava
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.google.common.base.Objects; | |
| public class Address { | |
| ... | |
| @Override | |
| public boolean equals(Object obj) { | |
| if (obj == null) return false; | |
| if (getClass() != obj.getClass()) return false; | |
| final Address other = (Address) obj; | |
| return Objects.equal(this.houseNumber, other.houseNumber) | |
| && Objects.equal(this.street, other.street) | |
| && Objects.equal(this.city, other.city) | |
| && Objects.equal(this.stateOrProvince, other.stateOrProvince) | |
| && Objects.equal(this.country, other.country); | |
| } | |
| @Override | |
| public int hashCode() { | |
| return Objects.hashCode( | |
| this.houseNumber, this.street, this.city, this.stateOrProvince, this.country); | |
| } | |
| @Override | |
| public String toString() { | |
| return Objects.toStringHelper(this) | |
| .add("houseNumber", houseNumber) | |
| .add("street", street) | |
| .toString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment