001/* 002 * Copyright 2020 Global Biodiversity Information Facility (GBIF) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.gbif.api.model.collections; 017 018import org.gbif.api.model.registry.LenientEquals; 019import org.gbif.api.model.registry.PrePersist; 020import org.gbif.api.vocabulary.Country; 021 022import java.io.Serializable; 023import java.util.Objects; 024import java.util.StringJoiner; 025 026import javax.annotation.Nullable; 027import javax.validation.constraints.Null; 028 029/** The particulars of the place where a institution of collection is situated. */ 030@SuppressWarnings("unused") 031public class Address implements Serializable, LenientEquals<Address> { 032 033 private Integer key; 034 private String address; 035 private String city; 036 private String province; 037 private String postalCode; 038 private Country country; 039 040 /** Unique identifier, assigned by the persistence store. */ 041 @Null(groups = {PrePersist.class}) 042 public Integer getKey() { 043 return key; 044 } 045 046 public void setKey(Integer key) { 047 this.key = key; 048 } 049 050 /** Textual direction of this address. */ 051 public String getAddress() { 052 return address; 053 } 054 055 public void setAddress(String address) { 056 this.address = address; 057 } 058 059 /** City where this address is located. */ 060 public String getCity() { 061 return city; 062 } 063 064 public void setCity(String city) { 065 this.city = city; 066 } 067 068 /** Province, region or area where this address is located. */ 069 public String getProvince() { 070 return province; 071 } 072 073 public void setProvince(String province) { 074 this.province = province; 075 } 076 077 /** International postal code of this address. */ 078 public String getPostalCode() { 079 return postalCode; 080 } 081 082 public void setPostalCode(String postalCode) { 083 this.postalCode = postalCode; 084 } 085 086 /** Country where this address is located. */ 087 @Nullable 088 public Country getCountry() { 089 return country; 090 } 091 092 public void setCountry(Country country) { 093 this.country = country; 094 } 095 096 @Override 097 public boolean equals(Object o) { 098 if (this == o) return true; 099 if (o == null || getClass() != o.getClass()) return false; 100 Address address1 = (Address) o; 101 return Objects.equals(key, address1.key) 102 && Objects.equals(address, address1.address) 103 && Objects.equals(city, address1.city) 104 && Objects.equals(province, address1.province) 105 && Objects.equals(postalCode, address1.postalCode) 106 && country == address1.country; 107 } 108 109 @Override 110 public int hashCode() { 111 return Objects.hash(key, address, city, province, postalCode, country); 112 } 113 114 @Override 115 public String toString() { 116 return new StringJoiner(", ", Address.class.getSimpleName() + "[", "]") 117 .add("key=" + key) 118 .add("address='" + address + "'") 119 .add("city='" + city + "'") 120 .add("province='" + province + "'") 121 .add("postalCode='" + postalCode + "'") 122 .add("country=" + country) 123 .toString(); 124 } 125 126 @Override 127 public boolean lenientEquals(Address other) { 128 if (this == other) { 129 return true; 130 } 131 return Objects.equals(address, other.address) 132 && Objects.equals(city, other.city) 133 && Objects.equals(province, other.province) 134 && Objects.equals(postalCode, other.postalCode) 135 && country == other.country; 136 } 137}