001/******************************************************************************* 002 * Copyright 2017 The MIT Internet Trust Consortium 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.mitre.openid.connect.model; 017 018import javax.persistence.Basic; 019import javax.persistence.Column; 020import javax.persistence.Entity; 021import javax.persistence.GeneratedValue; 022import javax.persistence.GenerationType; 023import javax.persistence.Id; 024import javax.persistence.Table; 025 026@Entity 027@Table(name="address") 028public class DefaultAddress implements Address { 029 030 private static final long serialVersionUID = -1304880008685206811L; 031 032 private Long id; 033 private String formatted; 034 private String streetAddress; 035 private String locality; 036 private String region; 037 private String postalCode; 038 private String country; 039 040 /** 041 * Empty constructor 042 */ 043 public DefaultAddress() { 044 045 } 046 047 /** 048 * Copy constructor from an existing address. 049 * @param address 050 */ 051 public DefaultAddress(Address address) { 052 setFormatted(address.getFormatted()); 053 setStreetAddress(address.getStreetAddress()); 054 setLocality(address.getLocality()); 055 setRegion(address.getRegion()); 056 setPostalCode(address.getPostalCode()); 057 setCountry(address.getCountry()); 058 } 059 060 /** 061 * @return the formatted address string 062 */ 063 @Override 064 @Basic 065 @Column(name = "formatted") 066 public String getFormatted() { 067 return formatted; 068 } 069 /** 070 * @param formatted the formatted address to set 071 */ 072 @Override 073 public void setFormatted(String formatted) { 074 this.formatted = formatted; 075 } 076 /** 077 * @return the streetAddress 078 */ 079 @Override 080 @Basic 081 @Column(name="street_address") 082 public String getStreetAddress() { 083 return streetAddress; 084 } 085 /** 086 * @param streetAddress the streetAddress to set 087 */ 088 @Override 089 public void setStreetAddress(String streetAddress) { 090 this.streetAddress = streetAddress; 091 } 092 /** 093 * @return the locality 094 */ 095 @Override 096 @Basic 097 @Column(name = "locality") 098 public String getLocality() { 099 return locality; 100 } 101 /** 102 * @param locality the locality to set 103 */ 104 @Override 105 public void setLocality(String locality) { 106 this.locality = locality; 107 } 108 /** 109 * @return the region 110 */ 111 @Override 112 @Basic 113 @Column(name = "region") 114 public String getRegion() { 115 return region; 116 } 117 /** 118 * @param region the region to set 119 */ 120 @Override 121 public void setRegion(String region) { 122 this.region = region; 123 } 124 /** 125 * @return the postalCode 126 */ 127 @Override 128 @Basic 129 @Column(name="postal_code") 130 public String getPostalCode() { 131 return postalCode; 132 } 133 /** 134 * @param postalCode the postalCode to set 135 */ 136 @Override 137 public void setPostalCode(String postalCode) { 138 this.postalCode = postalCode; 139 } 140 /** 141 * @return the country 142 */ 143 @Override 144 @Basic 145 @Column(name = "country") 146 public String getCountry() { 147 return country; 148 } 149 /** 150 * @param country the country to set 151 */ 152 @Override 153 public void setCountry(String country) { 154 this.country = country; 155 } 156 157 /** 158 * @return the id 159 */ 160 @Override 161 @Id 162 @GeneratedValue(strategy=GenerationType.IDENTITY) 163 @Column(name = "id") 164 public Long getId() { 165 return id; 166 } 167 168 /** 169 * @param id the id to set 170 */ 171 public void setId(Long id) { 172 this.id = id; 173 } 174 175 /* (non-Javadoc) 176 * @see java.lang.Object#hashCode() 177 */ 178 @Override 179 public int hashCode() { 180 final int prime = 31; 181 int result = 1; 182 result = prime * result + ((country == null) ? 0 : country.hashCode()); 183 result = prime * result + ((formatted == null) ? 0 : formatted.hashCode()); 184 result = prime * result + ((id == null) ? 0 : id.hashCode()); 185 result = prime * result + ((locality == null) ? 0 : locality.hashCode()); 186 result = prime * result + ((postalCode == null) ? 0 : postalCode.hashCode()); 187 result = prime * result + ((region == null) ? 0 : region.hashCode()); 188 result = prime * result + ((streetAddress == null) ? 0 : streetAddress.hashCode()); 189 return result; 190 } 191 192 /* (non-Javadoc) 193 * @see java.lang.Object#equals(java.lang.Object) 194 */ 195 @Override 196 public boolean equals(Object obj) { 197 if (this == obj) { 198 return true; 199 } 200 if (obj == null) { 201 return false; 202 } 203 if (!(obj instanceof DefaultAddress)) { 204 return false; 205 } 206 DefaultAddress other = (DefaultAddress) obj; 207 if (country == null) { 208 if (other.country != null) { 209 return false; 210 } 211 } else if (!country.equals(other.country)) { 212 return false; 213 } 214 if (formatted == null) { 215 if (other.formatted != null) { 216 return false; 217 } 218 } else if (!formatted.equals(other.formatted)) { 219 return false; 220 } 221 if (id == null) { 222 if (other.id != null) { 223 return false; 224 } 225 } else if (!id.equals(other.id)) { 226 return false; 227 } 228 if (locality == null) { 229 if (other.locality != null) { 230 return false; 231 } 232 } else if (!locality.equals(other.locality)) { 233 return false; 234 } 235 if (postalCode == null) { 236 if (other.postalCode != null) { 237 return false; 238 } 239 } else if (!postalCode.equals(other.postalCode)) { 240 return false; 241 } 242 if (region == null) { 243 if (other.region != null) { 244 return false; 245 } 246 } else if (!region.equals(other.region)) { 247 return false; 248 } 249 if (streetAddress == null) { 250 if (other.streetAddress != null) { 251 return false; 252 } 253 } else if (!streetAddress.equals(other.streetAddress)) { 254 return false; 255 } 256 return true; 257 } 258 259}