Source code: recoin/util/TimeLog.java
1
2 package recoin.util;
3
4 import java.io.Serializable;
5 import java.util.Vector;
6 import java.util.Calendar;
7 import java.util.NoSuchElementException;
8
9 /**
10 * A TimeLog can be used to record a sequence of phases or processes.
11 * <br><br>
12 * To do so an unlimitited number of DurationStamp objects can be added.
13 * The first DurationStamp added to the TimeLog should be used to represent
14 * the overall process. There is also a special constructor for this case.
15 * @author Jan H. Scheufen
16 * @version 0.2.9
17 */
18 public class TimeLog implements Serializable
19 {
20 /**
21 * The DurationStamp objects
22 */
23 private Vector durationStamps;
24 /**
25 * A Calendar object. Static so everybody can use it without the need for a
26 * TimeLog object.
27 */
28 public static Calendar calendar = Calendar.getInstance();;
29
30 /**
31 * Creates an empty TimeLog.
32 */
33 public TimeLog()
34 {
35 durationStamps = new Vector();
36 }
37
38 /**
39 * Creates a TimeLog with a DurationStamp initiated to the current time if specified
40 * by the boolean parameter.
41 * If the parameter is false, the constructor behaves just like the empty constructor.
42 * @param init the boolean parameter
43 */
44 public TimeLog(boolean init)
45 {
46 durationStamps = new Vector();
47 if( init )
48 addDurationStamp( new DurationStamp( calendar.getTimeInMillis() ) );
49 }
50
51 /**
52 * Adds the specified DurationStamp to the TimeLog.
53 * @param stamp the DurationStamp to be added
54 */
55 public void addDurationStamp(DurationStamp stamp)
56 {
57 durationStamps.add(stamp);
58 }
59
60 /**
61 * Returns the DurationStamps in this TimeLog.
62 * @return the DurationStamp objects in a Vector
63 */
64 public Vector getDurationStamps()
65 {
66 return durationStamps;
67 }
68
69 /**
70 * Returns the first DurationStamp added to this TimeLog.
71 * @return DurationStamp
72 * @throws NoSuchElementException
73 */
74 public DurationStamp getInitialStamp() throws NoSuchElementException
75 {
76 return (DurationStamp)durationStamps.firstElement();
77 }
78
79 /**
80 * Closes this TimeLog by setting the end time of the initial DurationStamp
81 * that represents the overall process.
82 * @throws NoSuchElementException
83 */
84 public void closeTimeLog() throws NoSuchElementException
85 {
86 getInitialStamp().setEndTime( calendar.getTimeInMillis() );
87 }
88
89 }