📄 rundatabo.java
字号:
/* @LICENSE_COPYRIGHT@ */
package net.sf.irunninglog.businessobject;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.irunninglog.canonical.CanonicalUtilities;
import net.sf.irunninglog.canonical.RunData;
import net.sf.irunninglog.util.ConstantValues;
import net.sf.irunninglog.util.ConversionException;
import net.sf.irunninglog.util.Conversions;
import net.sf.irunninglog.util.DTO;
import net.sf.irunninglog.util.FatalRuntimeException;
import net.sf.irunninglog.util.Utilities;
import net.sf.irunninglog.validation.ValidationError;
import net.sf.irunninglog.validation.ValidationUtilities;
/**
* Business object representing a <em>Run Data</em>. This is a POJO business
* object (BO) implementation that is used to represent <em>Run Data</em>
* entities within the application's business layer.
*
* @author <a href="mailto:allan_e_lewis@yahoo.com">Allan Lewis</a>
* @version $Revision: 1.3 $ $Date: 2005/06/29 23:26:53 $
* @since iRunningLog 1.0
*/
public class RunDataBO extends HasGeneratedIdBO {
/** <code>Log</code> instance for this class. */
private static final Log LOG = LogFactory.getLog(RunDataBO.class);
/** The BO's <em>date</em> field. */
private Date mDate;
/** The BO's <em>distance</em> field. */
private BigDecimal mDistance;
/** The BO's <em>untis</em> field. */
private String mUnits;
/** The BO's <em>time</em> field. */
private Long mTime;
/** The BO's <em>route</em> field. */
private String mRoute;
/** The BO's <em>run type</em> field. */
private String mRunType;
/** The BO's <em>shoes</em> field. */
private String mShoes;
/** The BO's <em>comments</em> field. */
private String mComments;
/**
* Create a new business object instance.
*
* @deprecated Use the <code>BusinessObjectFactory</code> to obtain new
* instances
* @see BusinessObjectFactory#newInstance(String)
*/
public RunDataBO() {
super();
}
/**
* Get the value of the BO's <em>date</em> field.
*
* @return The current value of the <em>date</em> field
*/
public Date getDate() {
return mDate;
}
/**
* Set the value of the BO's <em>date</em> field.
*
* @param value The value to be set onto the <em>date</em> field
*/
public void setDate(Date value) {
mDate = value;
}
/**
* Get the value of the BO's <em>distance</em> field.
*
* @return The current value of the <em>distance</em> field
*/
public BigDecimal getDistance() {
return mDistance;
}
/**
* Set the value of the BO's <em>distance</em> field.
*
* @param value The value to be set onto the <em>distance</em> field
*/
public void setDistance(BigDecimal value) {
mDistance = value;
}
/**
* Get the value of the BO's <em>units</em> field.
*
* @return The current value of the <em>units</em> field
*/
public String getUnits() {
return mUnits;
}
/**
* Set the value of the BO's <em>units</em> field.
*
* @param value The value to be set onto the <em>units</em> field
*/
public void setUnits(String value) {
mUnits = value;
}
/**
* Get the value of the BO's <em>time</em> field.
*
* @return The current value of the <em>time</em> field
*/
public Long getTime() {
return mTime;
}
/**
* Set the value of the BO's <em>time</em> field.
*
* @param value The value to be set onto the <em>time</em> field
*/
public void setTime(Long value) {
mTime = value;
}
/**
* Get the value of the BO's <em>pace</em> field.
*
* @return The current value of the <em>pace</em> field
*/
public String getPace() {
if (getTime() == null || getDistance() == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("getPace: Time and/or distance null; returning null");
}
return null;
} else if (getDistance().compareTo(ConstantValues.BD_ZERO) == 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("getPace: Distance is zero; returning null");
}
return null;
}
long time = getTime().longValue();
double distance = getDistance().doubleValue();
if (LOG.isDebugEnabled()) {
LOG.debug("getPace: Time is " + time);
LOG.debug("getPace: Distance is " + distance);
}
time = (long) (time / distance);
if (LOG.isDebugEnabled()) {
LOG.debug("getPace: Pace is " + time);
}
try {
return (time == Double.NaN) ? null
: Conversions.timeToString(new Long(time));
} catch (ConversionException ex) {
if (LOG.isDebugEnabled()) {
LOG.debug("getPace: Unable to convert " + time
+ ", returning null");
}
return null;
}
}
/**
* Get the value of the BO's <em>route</em> field.
*
* @return The current value of the <em>route</em> field
*/
public String getRoute() {
return mRoute;
}
/**
* Set the value of the BO's <em>route</em> field.
*
* @param value The value to be set onto the <em>route</em> field
*/
public void setRoute(String value) {
mRoute = value;
}
/**
* Get the value of the BO's <em>run type</em> field.
*
* @return The current value of the <em>run type</em> field
*/
public String getRunType() {
return mRunType;
}
/**
* Set the value of the BO's <em>run type</em> field.
*
* @param value The value to be set onto the <em>run type</em> field
*/
public void setRunType(String value) {
mRunType = value;
}
/**
* Get the value of the BO's <em>shoes</em> field.
*
* @return The current value of the <em>shoes</em> field
*/
public String getShoes() {
return mShoes;
}
/**
* Set the value of the BO's <em>shoes</em> field.
*
* @param value The value to be set onto the <em>shoes</em> field
*/
public void setShoes(String value) {
mShoes = value;
}
/**
* Get the value of the BO's <em>comments</em> field.
*
* @return The current value of the <em>comments</em> field
*/
public String getComments() {
return mComments;
}
/**
* Set the value of the BO's <em>comments</em> field.
*
* @param value The value to be set onto the <em>comments</em> field
*/
public void setComments(String value) {
mComments = value;
}
/**
* Get a data transfer objects containing values that represent the current
* state of this BO. This is a template method that is called from the
* final method <code>getValues</code> in <code>BaseBO</code>.
*
* @return The data transfer object, populated with the appropriate values
* @see BaseBO#getValues()
*/
protected DTO getValuesInternal() {
DTO valueObject = super.getValuesInternal();
String value = null;
Long lValue = null;
if (LOG.isDebugEnabled()) {
LOG.debug("getValuesInternal: Contents of the value object "
+ " (before) " + valueObject);
}
valueObject.setCanonicalId(RunData.CANONICAL_ID);
value = Conversions.dateToString(getDate());
valueObject.setValue(RunData.FIELD_DATE, value);
value = Conversions.decimalToString(getDistance());
valueObject.setValue(RunData.FIELD_DISTANCE, value);
value = getUnits();
valueObject.setValue(RunData.FIELD_UNITS, value);
lValue = getTime();
try {
value = Conversions.timeToString(lValue);
} catch (ConversionException ex) {
throw new FatalRuntimeException(ex);
}
valueObject.setValue(RunData.FIELD_TIME, value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -