KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > community > modules > TimeStamp


1 /* -*- tab-width: 4; -*-
2  
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5  
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8  
9 */

10
11 package org.mmbase.applications.community.modules;
12
13 import java.util.Date JavaDoc;
14
15 /**
16  * Creates a timestamp value out of two integer values.
17  * Supposedly needed because the Informix setup had no configuration
18  * for long values (in which the timestamps are expressed), which
19  * means they need be store as two integers instead.
20  * @deprecated Do not use this class. Store timestamps as Long or Date instead.
21  *
22  * @author Dirk-Jan Hoekstra
23  * @author Pierre van Rooden
24  * @version $Id: TimeStamp.java,v 1.8 2005/01/30 16:46:35 nico Exp $
25  */

26
27 public class TimeStamp extends Date JavaDoc
28 {
29
30     /**
31      * the 16 least significant bits of the timestamp value
32      */

33     private int low = 0;
34     /**
35     * the 16 most significant bits of the timestamp value
36     */

37     private int high = 0;
38
39     /**
40     * Creates a TimeStamp based on the current time.
41     */

42     public TimeStamp()
43     { /* POST: Creates a TimeStamp with the current time.
44        */

45         this(System.currentTimeMillis());
46     }
47
48     /**
49     * Creates a TimeStamp based on a specified time.
50     * @param time the time in milliseconds since 1/1/1970
51     */

52     public TimeStamp(long time)
53     {
54         setTime(time);
55         low = (int)(time & 0xFFFFFFFFL);
56         high = (int)(time >>> 32);
57     }
58
59      /**
60      * Creates a TimeStamp based on a specified time.
61      * @param low the 16 least significant bits of a time value (a long
62      * representing milliseconds since 1/1/1970
63      * @param high the 16 most significant bits of the time value
64      */

65     public TimeStamp(Integer JavaDoc low, Integer JavaDoc high)
66     {
67         this(); // Create this with currenttime
68
if ((low!=null) && (high!=null))
69             setTimeLowHigh(low.intValue(), high.intValue());
70     }
71
72     public TimeStamp(int low, int high)
73     {
74         setTimeLowHigh(low, high);
75     }
76     
77     /**
78     * Creates a TimeStamp based on a specified time.
79     * @param low the 16 least significant bits of a time value (a long
80     * representing milliseconds since 1/1/1970
81     * @param high the 16 most significant bits of the time value
82     */

83     private void setTimeLowHigh(int low, int high)
84     { /* PRE: Low has to contain the 16 least significant bits and high the 16 most significant bits of a long value.
85        * The long value is interpeted as the milliseconds passed since January 1, 1970, 00:00:00 GMT.\
86        * POST: Take the two int values together and merge them into a long value.
87        */

88
89         long highlong = high;
90         highlong <<= 32;
91         long time;
92         if (low<0) { // sign bit is up
93
long lowlong = low;
94             lowlong &= 0xFFFFFFFFL;
95             time = highlong + lowlong;
96         }
97         else {
98             time = highlong + low;
99         }
100         setTime(time);
101     }
102
103     /**
104     * Retrieve the 16 least significant bits of a time value (a long
105     * representing milliseconds since 1/1/1970.
106     */

107     public int lowIntegerValue()
108     {
109         return low;
110     }
111
112     /**
113     * Retrieve the 16 most significant bits of a time value (a long
114     * representing milliseconds since 1/1/1970.
115     */

116     public int highIntegerValue()
117     {
118         return high;
119     }
120 }
121
Popular Tags