package cz.vutbr.feec.session.gnp;

import java.net.InetAddress;
import org.apache.commons.lang.builder.ToStringBuilder;

import cz.vutbr.feec.session.ping.IAddress;

/**
 * The Class LandmarkInfo.
 */
public class LandmarkInfo implements IAddress {

	/** The address. */
	private InetAddress address;
	
	/** The hostname. */
	private String hostname;
	
	/** The hostaddr. */
	private String hostaddr;

	/** The latitude. */
	private float latitude = Float.NaN;
	
	/** The longitude. */
	private float longitude = Float.NaN;

	private int continent = -1;
	
	private boolean fixed = false;
	private float distanceToHostComputed = Float.POSITIVE_INFINITY;
	private float distanceToHostMeassured = Float.POSITIVE_INFINITY;
	
	public LandmarkInfo() {}
	/**
	 * Instantiates a new landmark info.
	 * 
	 * @param fixed the fixed or dynamic 
	 * @param address the address
	 * @param continent number
	 */
	public LandmarkInfo(boolean fixed, InetAddress address, int continent) {
		this.address = address;
		this.fixed = fixed;
		hostname = address.getCanonicalHostName();
		hostaddr = address.getHostAddress();
		this.continent = continent;
	}

	/**
	 * Instantiates a new landmark info.
	 * 
	 * @param fixed for fixed true and for dynamic false 
	 * @param address the address
	 * @param latitude the latitude
	 * @param longitude the longitude
	 * @param continent number
	 */
	public LandmarkInfo(boolean fixed, InetAddress address, float latitude, float longitude, int continent) {
		this.fixed = fixed;
		this.address = address;
		this.latitude = latitude;
		this.longitude = longitude;
		this.continent = continent;

		hostname = address.getCanonicalHostName();
		hostaddr = address.getHostAddress();
	}

	public boolean isKnownPosition() {
		return (latitude != Float.NaN && longitude != Float.NaN);
	}
	
	public boolean isFixed() {
		return this.fixed;
	}

	/**
	 * Gets the address.
	 * 
	 * @return the address
	 */
	public InetAddress getAddress() {
		return address;
	}

	/**
	 * Gets the latitude.
	 * 
	 * @return the latitude
	 */
	public float getLatitude() {
		return latitude;
	}

	/**
	 * Gets the longitude.
	 * 
	 * @return the longitude
	 */
	public float getLongitude() {
		return longitude;
	}

	/**
	 * Sets the address.
	 * 
	 * @param address the new address
	 */
	public void setAddress(InetAddress address) {
		this.address = address;
	}

	/**
	 * Sets the latitude.
	 * 
	 * @param latitude the new latitude
	 */
	public void setLatitude(float latitude) {
		this.latitude = latitude;
	}

	/**
	 * Sets the longitude.
	 * 
	 * @param longitude the new longitude
	 */
	public void setLongitude(float longitude) {
		this.longitude = longitude;
	}

	public void setPosition(float lat, float lng) {
		latitude = lat;
		longitude = lng;
	}
	
	/**
	 * Gets the host name.
	 * 
	 * @return the hostname
	 */
	public String getHostName() {
		return hostname;
	}

	/**
	 * Gets the host address.
	 * 
	 * @return the hostaddr
	 */
	public String getHostAddress() {
		return hostaddr;
	}

	/**
	 * To string.
	 * 
	 * @return the string
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("hostaddr", this.hostaddr)
				.append("longitude", this.longitude).append("hostname",
						this.hostname).append("latitude", this.latitude)
				.append("address", this.address).toString();
	}

	public void setDistanceToHostComputed(float distance) {
		distanceToHostComputed = distance;
	}
	
	public float getDistanceToHostComputed() {
		return distanceToHostComputed;
	}
	
	public void setDistanceToHostMeassured(float distance) {
		distanceToHostMeassured = distance;
	}
	
	public float getDistanceToHostMeassured() {
		return distanceToHostMeassured;
	}
	
	public void setContinent(int continent) {
		this.continent = continent;
	}
	
	public int getContinent() {
		return this.continent;
	}

}
