Skip to content

Instantly share code, notes, and snippets.

@goindwalia
Created May 18, 2017 07:03
Show Gist options
  • Save goindwalia/80ab1a072e2e98a888d53975d550e78b to your computer and use it in GitHub Desktop.
Save goindwalia/80ab1a072e2e98a888d53975d550e78b to your computer and use it in GitHub Desktop.
/* Java program */
public class Address {
private String street;
private int streetNumber;
private String postCode;
private String city;
private Country country;
public Address(String street, int streetNumber, String postCode, String city, Country country) {
this.street = street;
this.streetNumber = streetNumber;
this.postCode = postCode;
this.city = city;
this.country = country;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Address address = (Address) o;
if (streetNumber != address.streetNumber) return false;
if (!street.equals(address.street)) return false;
if (!postCode.equals(address.postCode)) return false;
if (!city.equals(address.city)) return false;
return country == address.country;
}
@Override
public int hashCode() {
int result = street.hashCode();
result = 31 * result + streetNumber;
result = 31 * result + postCode.hashCode();
result = 31 * result + city.hashCode();
result = 31 * result + (country != null ? country.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Address{" +
"street='" + street + '\'' +
", streetNumber=" + streetNumber +
", postCode='" + postCode + '\'' +
", city='" + city + '\'' +
", country=" + country +
'}';
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public int getStreetNumber() {
return streetNumber;
}
public void setStreetNumber(int streetNumber) {
this.streetNumber = streetNumber;
}
public String getPostCode() {
return postCode;
}
public void setPostCode(String postCode) {
this.postCode = postCode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment