KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > db > simple > types > Incarnation


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.db.simple.types;
15
16 import java.io.*;
17 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
18
19 public class Incarnation implements Serializable
20 {
21     private long m_high;
22     private long m_low;
23     private transient boolean m_dirty;
24     private static final long MAX_VALUE = 4294967295L;
25
26     static final long serialVersionUID = -6506601918195268342L;
27
28
29     private Incarnation(long high, long low) // for testing
30
{
31     m_high = high;
32     m_low = low;
33     m_dirty = true;
34     }
35
36
37     public Incarnation()
38     {
39     m_high = 0;
40     m_low = 1;
41     m_dirty = true;
42     }
43
44
45     public Incarnation(IncarnationNumber inc)
46     {
47     m_high = inc.high;
48     m_low = inc.low;
49     m_dirty = true;
50     }
51
52
53     public IncarnationNumber getIncarnationNumber()
54     {
55     return new IncarnationNumber((int)m_high, (int)m_low);
56     }
57
58   
59     public int compareTo(Incarnation inc)
60     {
61     int result;
62
63     if ((m_high < inc.m_high) || (m_high == inc.m_high && m_low < inc.m_low))
64         result = -1;
65     else if (m_high == inc.m_high && m_low == inc.m_low)
66         result = 0;
67     else
68         result = 1;
69
70     return result;
71     }
72
73
74     public void increment()
75     {
76     if (m_low < MAX_VALUE)
77         m_low++;
78     else {
79         m_low = 0;
80         m_high++;
81     }
82     m_dirty = true;
83     }
84
85
86     public boolean getDirty()
87     {
88     return m_dirty;
89     }
90
91
92     public String JavaDoc toString()
93     {
94     return "{" + m_high + "," + m_low + "}";
95     }
96
97
98     private void writeObject(ObjectOutputStream out)
99     throws IOException
100     {
101     out.defaultWriteObject();
102     m_dirty = false;
103     }
104
105
106     private void readObject(ObjectInputStream in)
107     throws IOException, ClassNotFoundException JavaDoc
108     {
109     in.defaultReadObject();
110     m_dirty = false;
111     }
112
113
114     /**************************** comment out this line for testing
115
116                   public static void main(String[] args)
117                   {
118                   Incarnation i1 = new Incarnation();
119                   System.out.println("i1 = " + i1);
120                   for (int i = 0; i < 50; i++)
121                   i1.increment();
122                   System.out.println("i1 = " + i1);
123                   i1.m_low = MAX_VALUE;
124                   System.out.println("i1 = " + i1);
125                   i1.increment();
126                   System.out.println("i1 = " + i1);
127
128                   i1 = new Incarnation(0, 1);
129                   Incarnation i2 = new Incarnation(0, 2);
130                   System.out.println("i1 (" + i1 + ") vs i2 (" + i2 + ") = " +
131                   i1.compareTo(i2));
132                   Incarnation i3 = new Incarnation(1, 0);
133                   System.out.println("i1 (" + i1 + ") vs i3 (" + i3 + ") = " +
134                   i1.compareTo(i3));
135                   System.out.println("i1 (" + i1 + ") vs i1 (" + i1 + ") = " +
136                   i1.compareTo(i1));
137                   System.out.println("i2 (" + i2 + ") vs i1 (" + i1 + ") = " +
138                   i2.compareTo(i1));
139                   }
140
141                   /**************************** comment out this line for testing */

142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
Popular Tags