package com.upweather.upobject;
import com.uplibrary.upexception.UPInvalidParameterException;
/**
* This class represent a generic model
* It's described by a name and a description.
* @author Giuseppe Persico - University of Naples "Parthenope"
*/
public final class UPModel {
private String modelName;
private String modelDescription;
/**
* The constructor will initialize the model with user defined parameters.
* @param modelName the model name.
* @param modelDescription the model description.
* @throws UPInvalidParameterException if model name or description are invalid.
*/
public UPModel(final String modelName, final String modelDescription) throws UPInvalidParameterException {
this.setModelName(modelName).setModelDescription(modelDescription);
}
/**
* This method returns the model name.
* @return the model name
*/
public final String getModelName() {
return this.modelName;
}
/**
* This method returns the model description.
* @return the model description
*/
public final String getModelDescription() {
return this.modelDescription;
}
/**
* Override of toString method
* It gives a representation of UPModel as string.
* @return UPModel in string format.
*/
@Override
public final String toString() {
return "CODE : "+this.modelName+"\nDESCRIPTION: "+this.modelDescription;
}
/**
* This method validates the model name.
* @param modelName the model name
* @return a reference to enable cascade calls.
* @throws UPInvalidParameterException if model name is null or an empty string
*/
protected final UPModel setModelName(final String modelName) throws UPInvalidParameterException {
if (modelName==null || modelName.isEmpty()) {
throw new UPInvalidParameterException("Model name can not be null or an empty string");
}
this.modelName = modelName;
return this;
}
/**
* This method validates the model description.
* @param modelDescription the model description.
* @return a reference to enable cascade calls
* @throws UPInvalidParameterException if model description is null or an empty string
*/
protected final UPModel setModelDescription(final String modelDescription) throws UPInvalidParameterException {
if (modelDescription==null) {
throw new UPInvalidParameterException("Model description can not be null");
} else if (modelDescription.isEmpty()) {
this.modelDescription = "No description supplied";
} else {
this.modelDescription = modelDescription;
}
return this;
}
}