Source code: recoin/util/DurationStamp.java
1
2 package recoin.util;
3
4 import java.io.Serializable;
5 import java.util.Date;
6
7 /**
8 * A DurationStamp can be used to measure a process that has a starting point and an
9 * end point.
10 * <br><br>
11 * The DurationStamp is given a name to identify the object or process that whose
12 * context this DurationStamp was created. This name is supposed to be used as a
13 * label for this DurationStamp.<br>
14 * Start and end of the process are stored internally as the number of milliseconds
15 * since January 1, 1970, 00:00:00 GMT.
16 * @author Jan H. Scheufen
17 * @version 0.2.9
18 */
19 public class DurationStamp implements Serializable
20 {
21 /**
22 * The start time of the process in milliseconds.
23 */
24 private long startTime;
25 /**
26 * The end time of the process in milliseconds.
27 */
28 private long endTime;
29 /**
30 * The name of the process represented by this DurationStamp.
31 */
32 private String name;
33
34 /**
35 * Creates a DurationStamp with the specified start time.
36 * @param initTime the start time as long
37 */
38 public DurationStamp(long initTime)
39 {
40 startTime = initTime;
41 }
42
43 /**
44 * Returns the duration of this DurationStamp in milliseconds. If the end time of
45 * the DurationStamp has not been set, 0 is returned.
46 * @return the duration of this DurationStamp as long
47 */
48 public long getDurationInMillis()
49 {
50 if( endTime != 0 )
51 return endTime-startTime;
52 else
53 return 0;
54 }
55
56 /**
57 * Returns the end time of this DurationStamp as a java.util.Date.
58 * @return the end time as a Date
59 */
60 public Date getEndDate()
61 {
62 return new Date(endTime);
63 }
64
65 /**
66 * Returns the start time of this DurationStamp as a java.util.Date.
67 * @return the start time as a Date
68 */
69 public Date getStartDate()
70 {
71 return new Date(startTime);
72 }
73
74 /**
75 * Returns the start time of this DurationStamp in milliseconds.
76 * @return the start time as long
77 */
78 public long getStartTimeInMillis()
79 {
80 return startTime;
81 }
82
83 /**
84 * Returns the end time of this DurationStamp in milliseconds.
85 * @return the end time as long
86 */
87 public long getEndTimeInMillis()
88 {
89 return endTime;
90 }
91
92 /**
93 * Sets the end time of this DurationStamp to the specified time.
94 * @param end the end time in milliseconds
95 */
96 public void setEndTime(long end)
97 {
98 endTime = end;
99 }
100
101 /**
102 * Sets the name of the DurationStamp to the specified name.
103 * @param n the new name
104 */
105 public void setName(String n)
106 {
107 name = n;
108 }
109
110 /**
111 * Returns the name of this DurationStamp.
112 * @return the name as String
113 */
114 public String getName()
115 {
116 return name;
117 }
118 }