1
2
3
4
5
6
7
8
9
10
11
12 package ca.spaz.cron.user;
13
14 import java.util.*;
15
16 public class UserMetrics implements Comparable {
17
18 private Date date;
19 private List metricList;
20
21 /***
22 * Create a new <code>UserMetrics</code> object with the current time
23 * as its date;
24 */
25 public UserMetrics() {
26 this(new Date());
27 }
28
29 /***
30 * Create a new <code>UserMetrics</code> object with the specified time
31 * as its date;
32 * @param date The time of this set of metrics.
33 */
34 public UserMetrics(Date date) {
35 if (null == date) {
36 throw new IllegalArgumentException("Must provide a Date");
37 }
38 this.date = date;
39 }
40
41 /***
42 * Get the date of this set of metrics.
43 * @return a <code>Date</code> object for the metrics.
44 */
45 public Date getMetricDate() {
46 return new Date(date.getTime());
47 }
48
49 /***
50 * Get a list of the metrics in this object. The list will not be modifiable.
51 * @return a <code>List</code> of metrics for this object.
52 */
53 public List getMetrics() {
54 return Collections.unmodifiableList(getMetricList());
55 }
56
57 /***
58 * Add a new metric to the list.
59 * @param metric the <code>Metric</code> to add.
60 */
61 public void addMetric(Metric metric) {
62 getMetricList().add(metric);
63 }
64
65 /***
66 * Remove a metric from the list.
67 * @param metric the <code>Metric</code> to remove.
68 */
69 public void removeMetric(Metric metric) {
70 getMetricList().remove(metric);
71 }
72
73 private List getMetricList() {
74 if (null == metricList) {
75 metricList = new ArrayList();
76 }
77 return metricList;
78 }
79
80
81
82
83 public int compareTo(Object arg0) {
84 return date.compareTo((Date) arg0);
85 }
86
87
88
89
90 public boolean equals(Object o) {
91 return date.equals(o);
92 }
93
94
95
96
97 public int hashCode() {
98 return date.hashCode();
99 }
100
101 }