001: package com.technoetic.xplanner.domain.virtual;
002:
003: import java.io.Serializable;
004: import java.math.BigDecimal;
005: import java.util.ArrayList;
006: import java.util.Calendar;
007: import java.util.Collection;
008: import java.util.Date;
009: import java.util.Hashtable;
010: import java.util.TreeMap;
011:
012: public class Timesheet implements Serializable {
013:
014: private ArrayList entries = new ArrayList();
015: private TreeMap dailyEntries = new TreeMap();
016: private String personName;
017: private BigDecimal total = new BigDecimal(0.0);
018: private Hashtable projectData = new Hashtable();
019: private Hashtable iterationData = new Hashtable();
020: private Hashtable storyData = new Hashtable();
021:
022: public Timesheet() {
023: }
024:
025: public Timesheet(Date startDate, Date endDate) {
026: Calendar cal = Calendar.getInstance();
027: cal.setTime(startDate);
028:
029: for (; cal.getTimeInMillis() <= endDate.getTime(); cal.add(
030: Calendar.DATE, 1)) {
031: dailyEntries.put(cal.getTime(), new DailyTimesheetEntry(cal
032: .getTime(), new BigDecimal(0.0)));
033: }
034: }
035:
036: public String getPersonName() {
037: return personName;
038: }
039:
040: public void setPersonName(String personName) {
041: this .personName = personName;
042: }
043:
044: public Collection getEntries() {
045: return entries;
046: }
047:
048: public Collection getDailyEntries() {
049: return dailyEntries.values();
050: }
051:
052: public void addEntry(TimesheetEntry entry) {
053: this .total = this .total.add(entry.getTotalDuration());
054: this .personName = entry.getPersonName();
055: this .entries.add(entry);
056: this .updateGroupedData(entry);
057: }
058:
059: public void addDailyEntry(DailyTimesheetEntry entry) {
060: DailyTimesheetEntry dailyEntry = (DailyTimesheetEntry) this .dailyEntries
061: .get(entry.getEntryDate());
062: dailyEntry.setTotalDuration(dailyEntry.getTotalDuration().add(
063: entry.getTotalDuration()));
064:
065: this .dailyEntries.put(dailyEntry.getEntryDate(), dailyEntry);
066: }
067:
068: public BigDecimal getTotal() {
069: return this .total.setScale(1, BigDecimal.ROUND_HALF_EVEN);
070: }
071:
072: private void updateGroupedData(TimesheetEntry entry) {
073:
074: // Project Data
075: BigDecimal projectTotal = (BigDecimal) this .projectData
076: .get(entry.getProjectName());
077: if (projectTotal == null) {
078: projectTotal = new BigDecimal(0.0);
079: }
080: projectTotal = projectTotal.add(entry.getTotalDuration())
081: .setScale(1, BigDecimal.ROUND_HALF_EVEN);
082: this .projectData.put(entry.getProjectName(), projectTotal);
083:
084: // Iteration Data
085: BigDecimal iterationTotal = (BigDecimal) this .iterationData
086: .get(entry.getIterationName());
087: if (iterationTotal == null) {
088: iterationTotal = new BigDecimal(0.0);
089: }
090: iterationTotal = iterationTotal.add(entry.getTotalDuration())
091: .setScale(1, BigDecimal.ROUND_HALF_EVEN);
092: this .iterationData
093: .put(entry.getIterationName(), iterationTotal);
094:
095: // Iteration Data
096: BigDecimal storyTotal = (BigDecimal) this .storyData.get(entry
097: .getStoryName());
098: if (storyTotal == null) {
099: storyTotal = new BigDecimal(0.0);
100: }
101: storyTotal = storyTotal.add(entry.getTotalDuration()).setScale(
102: 1, BigDecimal.ROUND_HALF_EVEN);
103: this .storyData.put(entry.getStoryName(), storyTotal);
104: }
105:
106: public Hashtable getIterationData() {
107: return iterationData;
108: }
109:
110: public Hashtable getProjectData() {
111: return projectData;
112: }
113:
114: public Hashtable getStoryData() {
115: return storyData;
116: }
117: }
|