View Javadoc

1   // $Id: RateRow.java,v 1.2 2004/04/07 20:26:56 powerpete Exp $
2   // [JMP, 11.03.2004] Created this file.
3   package com.pnpconsult.zeiterfassung.table;
4   
5   import java.util.AbstractCollection;
6   import java.util.Iterator;
7   import java.util.SortedSet;
8   import java.util.TreeSet;
9   
10  import org.apache.commons.lang.StringUtils;
11  
12  import com.pnpconsult.zeiterfassung.model.AbstractBaseEntry;
13  import com.pnpconsult.zeiterfassung.util.NumberUtils;
14  
15  /***
16   * @author <a href="mailto:powerpete@users.sf.net">M. Petersen</a>
17   * @version $Id: RateRow.java,v 1.2 2004/04/07 20:26:56 powerpete Exp $
18   */
19  public class RateRow extends AbstractCollection
20  {
21      protected float rate;
22      protected float hours;
23      protected SortedSet users = new TreeSet();
24  
25      public boolean add(Object obj)
26      {
27          AbstractBaseEntry entry = (AbstractBaseEntry) obj;
28          rate = entry.getRate();
29          hours += entry.getHours();
30          users.add(entry.getUser().getDisplayName());
31          return true;
32      }
33      
34      public String getUserNames()
35      {
36          return StringUtils.join(users.iterator(), ", ");
37      }
38      
39      public String getHours()
40      {
41          return NumberUtils.formatShort(computeHours());
42      }
43      
44      public float computeHours()
45      {
46          return hours;
47      }
48      
49      public String getRate()
50      {
51          return NumberUtils.formatLong(computeRate());
52      }
53  
54      public float computeRate()
55      {
56          return rate;
57      }
58  
59      public Iterator iterator()
60      {
61          return users.iterator();
62      }
63  
64      public int size()
65      {
66          return users.size();
67      }
68      
69      public String getTotal()
70      {
71          return NumberUtils.formatLong(computeTotal());
72      }
73  
74      public float computeTotal()
75      {
76          return hours * rate;
77      }
78  }