KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > db > pse > 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.pse.types;
15
16 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
17
18
19 public class Incarnation
20 {
21   private long m_high;
22   private long m_low;
23   private static final long MAX_VALUE = 4294967295L;
24
25
26   private Incarnation(long high, long low) // for testing
27
{
28     m_high = high;
29     m_low = low;
30   }
31
32
33   public Incarnation()
34   {
35     m_high = 0;
36     m_low = 1;
37   }
38
39
40   public Incarnation(IncarnationNumber inc)
41   {
42     m_high = inc.high;
43     m_low = inc.low;
44   }
45
46
47   public IncarnationNumber getIncarnationNumber()
48   {
49     return new IncarnationNumber((int)m_high, (int)m_low);
50   }
51
52   
53   public int compareTo(Incarnation inc)
54   {
55     int result;
56
57     if ((m_high < inc.m_high) || (m_high == inc.m_high && m_low < inc.m_low))
58       result = -1;
59     else if (m_high == inc.m_high && m_low == inc.m_low)
60       result = 0;
61     else
62       result = 1;
63
64     return result;
65   }
66
67
68   public void increment()
69   {
70     if (m_low < MAX_VALUE)
71       m_low++;
72     else {
73       m_low = 0;
74       m_high++;
75     }
76   }
77
78
79   public String JavaDoc toString()
80   {
81     return "{" + m_high + "," + m_low + "}";
82   }
83
84
85   /**************************** comment out this line for testing
86
87   public static void main(String[] args)
88   {
89     Incarnation i1 = new Incarnation();
90     System.out.println("i1 = " + i1);
91     for (int i = 0; i < 50; i++)
92       i1.increment();
93     System.out.println("i1 = " + i1);
94     i1.m_low = MAX_VALUE;
95     System.out.println("i1 = " + i1);
96     i1.increment();
97     System.out.println("i1 = " + i1);
98
99     i1 = new Incarnation(0, 1);
100     Incarnation i2 = new Incarnation(0, 2);
101     System.out.println("i1 (" + i1 + ") vs i2 (" + i2 + ") = " +
102       i1.compareTo(i2));
103     Incarnation i3 = new Incarnation(1, 0);
104     System.out.println("i1 (" + i1 + ") vs i3 (" + i3 + ") = " +
105       i1.compareTo(i3));
106     System.out.println("i1 (" + i1 + ") vs i1 (" + i1 + ") = " +
107       i1.compareTo(i1));
108     System.out.println("i2 (" + i2 + ") vs i1 (" + i1 + ") = " +
109       i2.compareTo(i1));
110   }
111
112   /**************************** comment out this line for testing */

113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Popular Tags