📄 dayformbean.java
字号:
/* @LICENSE_COPYRIGHT@ */
package net.sf.irunninglog.servlet.formbean;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import net.sf.irunninglog.canonical.RunData;
import net.sf.irunninglog.util.ConstantValues;
/**
* Form bean representing a day of the week. This form bean can either
* represent a single day (along with a month and year), or as a 'placeholder'.
* Each instance may also have run data associated with it.
*
* @author <a href="mailto:allan_e_lewis@yahoo.com">Allan Lewis</a>
* @version $Revision: 1.1.1.1 $ $Date: 2005/06/23 01:49:00 $
* @since iRunningLog 1.0
*/
public final class DayFormBean extends FormBean {
/** The day of the month for this form bean. */
private int mDay;
/** The month for this form bean. */
private int mMonth;
/** The year for this form bean. */
private int mYear;
/** Whether this form bean is a placeholder or a 'real' day. */
private boolean mPlaceHolder;
/** Run data associated with this form bean. */
private RunDataFormBean mRunData;
/**
* Create a day form bean. This will create a new 'placeholder' form bean.
* The <code>getDay</code>, <code>getMonth</code>, and <code>getYear</code>
* methods will all return <code>-1</code>, and <code>isPlaceholder</code>
* will return <code>true</code>.
*/
public DayFormBean() {
this(-1, -1, -1, true);
}
/**
* Create a new day form bean to represent a specified day, month, and year
* combination. The <code>isPlaceholder</code> method will return <code>
* false</code> for this form bean.
*
* @param day The day of the month for this form bean
* @param month The month for this form bean
* @param year The year for this form bean
*/
public DayFormBean(int day, int month, int year) {
this(day, month, year, false);
}
/**
* Create a new day form bean.
*
* @param day The day of the month for this form bean
* @param month The month for this form bean
* @param year The year for this form bean
* @param placeHolder Whether or not this is a 'placeholder' form bean
*/
private DayFormBean(int day, int month, int year, boolean placeHolder) {
mPlaceHolder = placeHolder;
mDay = day;
mMonth = month;
mYear = year;
}
/**
* Get the day of the month for this form bean.
*
* @return The day of the month for this form bean, or -1 if this is a
* 'placeholder' form bean
*/
public int getDay() {
return mDay;
}
/**
* Get the month for this form bean.
*
* @return The month for this form bean, or -1 if this is a
* 'placeholder' form bean
*/
public int getMonth() {
return mMonth;
}
/**
* Get the year for this form bean.
*
* @return The year for this form bean, or -1 if this is a
* 'placeholder' form bean
*/
public int getYear() {
return mYear;
}
/**
* Determine whether or not this form bean is a 'placeholder' form bean, or
* a form bean representing an actual day.
*
* @return True if this form bean is a 'placeholder', false otherwise
*/
public boolean isPlaceholder() {
return mPlaceHolder;
}
/**
* Determine whether this form bean represents the current day.
*
* @return True if this form bean is represents the current day, false
* otherwise
*/
public boolean isCurrentDay() {
Calendar cal = GregorianCalendar.getInstance();
boolean currentYear = mYear == cal.get(Calendar.YEAR);
boolean currentMonth = mMonth == cal.get(Calendar.MONTH);
boolean currentDay = mDay == cal.get(Calendar.DAY_OF_MONTH);
return !isPlaceholder() && currentYear && currentMonth && currentDay;
}
/**
* Get the run data object associated with this form bean.
*
* @return The run data form bean associated with this form bean, or
* <code>null</code> if none is present
*/
public RunDataFormBean getRunData() {
return mRunData;
}
/**
* Set the run data object associated with this form bean.
*
* @param data The form bean to be associated with this form bean
*/
public void setRunData(RunDataFormBean data) {
mRunData = data;
}
/**
* Get the parameters to be used in editing the run data associated with
* this form bean. This will return the data needed by the application's
* view tier to identify the parameters needed to interact with the run
* data form bean associated with this bean.
*
* @return The map of parameters used to edit the run data for this bean
*/
public Map getEditRunDataParameters() {
Map params = new HashMap();
if (mRunData == null) {
params.put(ConstantValues.STRING_DAY, new Integer(mDay));
params.put(ConstantValues.STRING_MONTH, new Integer(mMonth));
params.put(ConstantValues.STRING_YEAR, new Integer(mYear));
} else {
params.put(RunData.FIELD_ID, mRunData.getId());
}
return Collections.unmodifiableMap(params);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -