001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.kra.budget.bo;
017:
018: import java.sql.Date;
019: import java.text.DateFormat;
020: import java.text.SimpleDateFormat;
021: import java.util.LinkedHashMap;
022:
023: import org.kuali.core.bo.PersistableBusinessObjectBase;
024: import org.kuali.kfs.KFSPropertyConstants;
025:
026: /**
027: *
028: */
029:
030: public class BudgetPeriod extends PersistableBusinessObjectBase
031: implements Comparable {
032: private static final long serialVersionUID = -479888264761887048L;
033:
034: private String documentNumber;
035: private Integer budgetPeriodSequenceNumber;
036: private Date budgetPeriodBeginDate;
037: private Date budgetPeriodEndDate;
038: private Integer budgetPeriodParticipantsNumber;
039:
040: /**
041: * Default no-arg constructor.
042: */
043: public BudgetPeriod() {
044: super ();
045: }
046:
047: public BudgetPeriod(String documentNumber,
048: Integer budgetPeriodSequenceNumber) {
049: this ();
050: this .documentNumber = documentNumber;
051: this .budgetPeriodSequenceNumber = budgetPeriodSequenceNumber;
052: }
053:
054: public BudgetPeriod(BudgetPeriod template) {
055: this ();
056: this .documentNumber = template.getDocumentNumber();
057: this .budgetPeriodSequenceNumber = template
058: .getBudgetPeriodSequenceNumber();
059: this .budgetPeriodBeginDate = template
060: .getBudgetPeriodBeginDate();
061: this .budgetPeriodEndDate = template.getBudgetPeriodEndDate();
062: this .budgetPeriodParticipantsNumber = template
063: .getBudgetPeriodParticipantsNumber();
064: }
065:
066: /**
067: * @return Returns the budgetNumber.
068: */
069: public String getDocumentNumber() {
070: return documentNumber;
071: }
072:
073: /**
074: * @param budgetNumber The budgetNumber to set.
075: */
076: public void setDocumentNumber(String documentNumber) {
077: this .documentNumber = documentNumber;
078: }
079:
080: /**
081: * @return Returns the budgetPeriodBeginDate.
082: */
083: public Date getBudgetPeriodBeginDate() {
084: return budgetPeriodBeginDate;
085: }
086:
087: /**
088: * @param budgetPeriodBeginDate The budgetPeriodBeginDate to set.
089: */
090: public void setBudgetPeriodBeginDate(Date budgetPeriodBeginDate) {
091: this .budgetPeriodBeginDate = budgetPeriodBeginDate;
092: }
093:
094: /**
095: * @return Returns the budgetPeriodEndDate.
096: */
097: public Date getBudgetPeriodEndDate() {
098: return budgetPeriodEndDate;
099: }
100:
101: /**
102: * @param budgetPeriodEndDate The budgetPeriodEndDate to set.
103: */
104: public void setBudgetPeriodEndDate(Date budgetPeriodEndDate) {
105: this .budgetPeriodEndDate = budgetPeriodEndDate;
106: }
107:
108: /**
109: * @return Returns the budgetPeriodSequenceNumber.
110: */
111: public Integer getBudgetPeriodSequenceNumber() {
112: if (budgetPeriodSequenceNumber == null) {
113: budgetPeriodSequenceNumber = Integer.valueOf("0");
114: }
115: return budgetPeriodSequenceNumber;
116: }
117:
118: /**
119: * @param budgetPeriodSequenceNumber The budgetPeriodSequenceNumber to set.
120: */
121: public void setBudgetPeriodSequenceNumber(
122: Integer budgetPeriodSequenceNumber) {
123: this .budgetPeriodSequenceNumber = budgetPeriodSequenceNumber;
124: }
125:
126: /**
127: * @return Returns the budgetPeriodParticipantsNumber.
128: */
129: public Integer getBudgetPeriodParticipantsNumber() {
130: return budgetPeriodParticipantsNumber;
131: }
132:
133: /**
134: * @param budgetPeriodParticipantsNumber The budgetPeriodParticipantsNumber to set.
135: */
136: public void setBudgetPeriodParticipantsNumber(
137: Integer budgetPeriodParticipantsNumber) {
138: this .budgetPeriodParticipantsNumber = budgetPeriodParticipantsNumber;
139: }
140:
141: protected LinkedHashMap toStringMapper() {
142: LinkedHashMap m = new LinkedHashMap();
143: m
144: .put(KFSPropertyConstants.DOCUMENT_NUMBER,
145: this .documentNumber);
146: m.put("budgetPeriodSequenceNumber",
147: this .budgetPeriodSequenceNumber);
148: return m;
149: }
150:
151: public String getBudgetPeriodLabel() {
152: DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
153:
154: String startDate = "(no start date)";
155: String endDate = "(no end date)";
156:
157: if (this .getBudgetPeriodBeginDate() != null) {
158: startDate = dateFormat.format(this
159: .getBudgetPeriodBeginDate());
160: }
161:
162: if (this .getBudgetPeriodEndDate() != null) {
163: endDate = dateFormat.format(this .getBudgetPeriodEndDate());
164: }
165:
166: return startDate + " - " + endDate;
167: }
168:
169: /**
170: * Implementing equals since I need contains to behave reasonably in a hashed datastructure.
171: *
172: * @see java.lang.Object#equals(java.lang.Object)
173: */
174: public boolean equals(Object obj) {
175: boolean equal = false;
176:
177: if (obj != null) {
178: if (this .getClass().equals(obj.getClass())) {
179: BudgetPeriod other = (BudgetPeriod) obj;
180:
181: if (this .getDocumentNumber().equals(
182: other.getDocumentNumber())
183: && this .getBudgetPeriodSequenceNumber().equals(
184: other.getBudgetPeriodSequenceNumber())
185: && ((this .getBudgetPeriodBeginDate() == null && other
186: .getBudgetPeriodEndDate() == null) || this
187: .getBudgetPeriodBeginDate()
188: .equals(
189: other
190: .getBudgetPeriodBeginDate()))
191: && ((this .getBudgetPeriodEndDate() == null && other
192: .getBudgetPeriodEndDate() == null) || this
193: .getBudgetPeriodEndDate().equals(
194: other.getBudgetPeriodEndDate()))) {
195:
196: equal = true;
197: }
198: }
199: }
200:
201: return equal;
202: }
203:
204: /**
205: * Calcluates hashCode based on current values of documentNumber and budgetPeriodSequenceNumber fields. Somewhat dangerous,
206: * since those fields are mutable, but I don't expect people to be editing those values directly for Periods stored in hashed
207: * datastructures. (this is based on Account.hashCode()) - TAD
208: *
209: * @see java.lang.Object#hashCode()
210: */
211: public int hashCode() {
212: String hashString = getDocumentNumber() + "|"
213: + getBudgetPeriodSequenceNumber()
214: + getBudgetPeriodBeginDate() + "|"
215: + getBudgetPeriodEndDate();
216:
217: return hashString.hashCode();
218: }
219:
220: /**
221: * @see java.lang.Comparable#compareTo(java.lang.Object)
222: */
223: public int compareTo(Object o) {
224: return this .getBudgetPeriodSequenceNumber().compareTo(
225: ((BudgetPeriod) o).getBudgetPeriodSequenceNumber());
226: }
227: }
|