Skip to content

Instantly share code, notes, and snippets.

@malys
Last active November 30, 2017 10:18
Show Gist options
  • Select an option

  • Save malys/836e8c8485931991731b to your computer and use it in GitHub Desktop.

Select an option

Save malys/836e8c8485931991731b to your computer and use it in GitHub Desktop.
[Guava Tips] #java #guava
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