package com.upweather.upobject;
import com.uplibrary.upexception.UPInvalidParameterException;
/**
* This class represent the place object
* A place has a name, an identifier,
* geographical coordinates, an extended name and a formatted address.
*/
public final class UPPlace {
/**
* Place name
*/
private String name;
/**
* Place identifier
*/
private String identifier;
/**
* Geographical coordinates
*/
private final UPCoordinate UPCoordinate;
/**
* Distance in kilometers
*/
private double distanceKm;
/**
* Place formatted address
*/
private String formattedAddress;
/**
* Complete name
*/
private String extendedName;
/**
* Constructor that gives a default value to the distance
* and to the coordinates.
*/
public UPPlace() {
this.distanceKm = 0.0;
this.UPCoordinate = new UPCoordinate();
}
/**
* Setter method that allows you to give a value to a place name
* @param name place name
* @return a reference to UPPlace class to enable cascade calls
* @throws UPInvalidParameterException when name is an empty string or a null value
*/
public final UPPlace setName(final String name) throws UPInvalidParameterException {
if (name==null || name.isEmpty()) {
throw new UPInvalidParameterException("Name can not be null or an empty string");
}
this.name = name;
return this;
}
/**
* Setter method that allows you to give a value to a place identifier.
* @param identifier place identifier
* @return a reference to UPPlace class to enable cascade calls
* @throws UPInvalidParameterException when identifier is an empty string or a null value
*/
public final UPPlace setIdentifier(final String identifier) throws UPInvalidParameterException {
if (identifier==null || identifier.isEmpty()) {
throw new UPInvalidParameterException("Identifier can not be null or an empty string");
}
this.identifier = identifier;
return this;
}
/**
* Setter method that allows you to specify a distance in kilometers that
* accepts a double value.
* @param distanceKm the distance in kilometers
* @return a reference to UPPlace class to enable cascade calls
*/
public final UPPlace setDistanceKm(final double distanceKm) {
if (distanceKm<0) {
this.distanceKm = 0.0;
} else {
this.distanceKm = distanceKm;
}
return this;
}
/**
* Setter method that allows you to specify a distance in kilometers that
* accepts a string and converts it in a double value
* @param distanceKm the distance in kilometers
* @return a reference to UPPlace class to enable cascade calls
*/
public final UPPlace setDistanceKm(final String distanceKm) {
try {
this.distanceKm = new Double(distanceKm);
} catch (NumberFormatException exc) {
this.distanceKm = 0.0;
}
return this;
}
/**
* Setter method that allows you to specify a formatted address for
* a place.
* @param formattedAddress the formatted address
* @return a reference to UPPlace class to enable cascade calls
* @throws UPInvalidParameterException when formattedAddress is an empty string or a null value
*/
public final UPPlace setFormattedAddress(final String formattedAddress) throws UPInvalidParameterException {
if (formattedAddress==null || formattedAddress.isEmpty()) {
throw new UPInvalidParameterException("Formatted address can not be null or an empty string");
}
this.formattedAddress = formattedAddress;
return this;
}
/**
* Setter method that allows you to specify a value for a place extended name.
* @param extendedName the full name
* @return a reference to UPPlace class to enable cascade calls
* @throws UPInvalidParameterException when extendedName is an empty string or a null value.
*/
public final UPPlace setExtendedName(final String extendedName) throws UPInvalidParameterException {
if (extendedName==null || extendedName.isEmpty()) {
throw new NullPointerException("Extended name can not be null or an empty string");
}
this.extendedName = extendedName;
return this;
}
/**
* Override of Object's toString() method that prints a place info directly.
* @return a formatted string containing place info.
*/
@Override
public final String toString() {
return "NAME : "+this.name+"\nIDENTIFIER : "+this.identifier+this.UPCoordinate +
"\nDISTANCE KM : "+this.distanceKm+"\nREGION ID : "+this.distanceKm+"\nFORMATT. ADD: "+this.formattedAddress+
"\nEXTENDED NM : "+this.extendedName;
}
/**
* Getter method that returns a place name.
* @return place name.
*/
public final String getName() {
return this.name;
}
/**
* Getter method that returns an identifier.
* @return place identifier.
*/
public final String getIdentifier() {
return this.identifier;
}
/**
* Getter method that returns a place coordinates.
* @return place coordinates.
*/
public final UPCoordinate getCoordinates() {
return this.UPCoordinate;
}
/**
* Getter method that returns a place distance in kilometers.
* @return place distance in kilometers.
*/
public final double getDistanceKm() {
return this.distanceKm;
}
/**
* Getter method that returns a place formatted address.
* @return place formatted address.
*/
public final String getFormattedAddress() {
return this.formattedAddress;
}
/**
* Getter method that returns a place extended name.
* @return place extended name.
*/
public final String getExtendedName() {
return this.extendedName;
}
}