com.evasion.entity.geolocation.Country Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of API Show documentation
Show all versions of API Show documentation
API de l'application modulaire evasion-en-ligne
The newest version!
/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package com.evasion.entity.geolocation;
import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Size;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/*
* pays
*/
/**
* Liste maintenue des villes de chaque pays dispo sur le site:
* http://www.geonames.org/
*
* @author sebastien.glon
*/
@Entity(name=Country.ENTITY_NAME)
@Table(name = Country.ENTITY_NAME)
@NamedQuery(name = "findByCtCode", query = "SELECT r FROM " + Country.ENTITY_NAME + " r WHERE r." + Country.ATTR_CODE + " = ?1")
public class Country extends Location {
/**
* *
* serialVersionUID.
*/
private static final long serialVersionUID = 1L;
public static final String ENTITY_NAME = "GEO_COUNTRY";
public static final String QUERY_FIND_BY_COUNTRY_CODE = "findByCtCode";
/**
* Taille max d'un code pays.
*/
public static final int CODE_MAX_LENGTH = 2;
/**
* Code pays normalise ISO 2.
*/
@Size(max=CODE_MAX_LENGTH)
@Column(unique = true, nullable = false, length = CODE_MAX_LENGTH+1)
private String code;
public static final String ATTR_CODE = "code";
@ManyToOne(optional = false)
@JoinColumn(name="CONTINENT_ID")
private Continent continent;
@Embedded
private Geoname geoname;
/**
* Constructeur par défaut pour la persistence.
*/
protected Country() {
}
/**
* Constructeur général.
* @param continent {@link Continent}
* @param code Code administratif sur 2 caractères.
* @param location Nom complet.
*/
public Country(Continent continent, String code, Location location) {
super(location);
this.continent = continent;
this.code = code;
}
/**
* Retourne le code pays.
* @return Le code du pays.
*/
public String getCode() {
return code;
}
/**
* Met à jour le code du pays.
* @param code Le code du pays.
*/
public void setCode(String code) {
this.code = code;
}
public Continent getContinent() {
return this.continent;
}
public void setContinent(Continent continent) {
this.continent = continent;
}
public Geoname getGeoname() {
return geoname;
}
public void setGeoname(Geoname geoname) {
this.geoname = geoname;
}
/**
* {@inheritDoc }
*/
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (!(obj instanceof Country)) {
return false;
}
Country rhs = (Country) obj;
return new EqualsBuilder().append(this.code, rhs.code).
isEquals();
}
/**
* @{@inheritDoc }
*/
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37).append(this.code).toHashCode();
}
/**
* @{@inheritDoc }
*/
@Override
public String toString() {
return new ToStringBuilder(this).append(this.getClass().getName()).
append("[").
append("code", code).
append("name=", this.getName()).
append("]").
toString();
}
}