/*******************************************************************************
* Copyright 2012 Christian Ternes and Thorsten Volland
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.businessmanager.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import org.businessmanager.i18n.ResourceBundleAccessor;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
@Entity
@Indexed
public class Address extends AbstractEntity implements HasDefault {
public enum AddressType {
SHIPPING("addresstype_shipping")
, BILLING("addresstype_billing");
private final String label;
private AddressType(String label) {
this.label = label;
}
public String getLabel() {
return ResourceBundleAccessor.getString(label);
}
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
@Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO)
private String street;
@Column
private String housenumber;
@Column
@Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO)
private String city;
@Column
@Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO)
private String zipCode;
@Column
private String forAttentionOf;
@Column
private String postOfficeBox;
@Column
@Enumerated(EnumType.STRING)
private AddressType scope = AddressType.BILLING;
@Column
private String country;
@Column
private Boolean isDefault;
@ManyToOne(targetEntity = Contact.class)
private Contact contact;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getHousenumber() {
return housenumber;
}
public void setHousenumber(String housenumber) {
this.housenumber = housenumber;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getForAttentionOf() {
return forAttentionOf;
}
public void setForAttentionOf(String forAttentionOf) {
this.forAttentionOf = forAttentionOf;
}
public String getPostOfficeBox() {
return postOfficeBox;
}
public void setPostOfficeBox(String postOfficeBox) {
this.postOfficeBox = postOfficeBox;
}
public AddressType getScope() {
return scope;
}
public void setScope(AddressType scope) {
this.scope = scope;
}
public Boolean getIsDefault() {
return isDefault;
}
public void setIsDefault(Boolean isDefault) {
this.isDefault = isDefault;
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((city == null) ? 0 : city.hashCode());
result = prime * result
+ ((forAttentionOf == null) ? 0 : forAttentionOf.hashCode());
result = prime * result
+ ((housenumber == null) ? 0 : housenumber.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result
+ ((isDefault == null) ? 0 : isDefault.hashCode());
result = prime * result
+ ((postOfficeBox == null) ? 0 : postOfficeBox.hashCode());
result = prime * result + ((scope == null) ? 0 : scope.hashCode());
result = prime * result + ((street == null) ? 0 : street.hashCode());
result = prime * result + ((zipCode == null) ? 0 : zipCode.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Address other = (Address) obj;
if (city == null) {
if (other.city != null)
return false;
} else if (!city.equals(other.city))
return false;
if (forAttentionOf == null) {
if (other.forAttentionOf != null)
return false;
} else if (!forAttentionOf.equals(other.forAttentionOf))
return false;
if (housenumber == null) {
if (other.housenumber != null)
return false;
} else if (!housenumber.equals(other.housenumber))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (isDefault == null) {
if (other.isDefault != null)
return false;
} else if (!isDefault.equals(other.isDefault))
return false;
if (postOfficeBox == null) {
if (other.postOfficeBox != null)
return false;
} else if (!postOfficeBox.equals(other.postOfficeBox))
return false;
if (scope == null) {
if (other.scope != null)
return false;
} else if (!scope.equals(other.scope))
return false;
if (street == null) {
if (other.street != null)
return false;
} else if (!street.equals(other.street))
return false;
if (zipCode == null) {
if (other.zipCode != null)
return false;
} else if (!zipCode.equals(other.zipCode))
return false;
return true;
}
@Override
public String toString() {
return "Address [id=" + id + ", street=" + street + ", housenumber="
+ housenumber + ", city=" + city + ", zipCode=" + zipCode
+ ", forAttentionOf=" + forAttentionOf + ", postOfficeBox="
+ postOfficeBox + ", scope=" + scope + ", isDefault="
+ isDefault + ", contact=" + contact + "]";
}
public void setCountry(String country) {
this.country = country;
}
public String getCountry() {
return country;
}
}