KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > core > Identifier


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb.core;
25
26 import java.io.*;
27
28 public final class Identifier implements Externalizable, Comparable JavaDoc
29 {
30     private long m_value = -1;
31     private boolean m_root = false;
32
33     public Identifier()
34     {
35     }
36
37     public Identifier(long value)
38     {
39         m_value = value;
40     }
41
42     public Identifier(long value, boolean root)
43     {
44         m_value = value;
45         m_root = root;
46     }
47
48     public final long getValue()
49     {
50         return m_value;
51     }
52
53     public final boolean isRoot()
54     {
55         return m_root;
56     }
57
58     public final int hashCode()
59     {
60         return (int) m_value;
61     }
62
63     public final boolean equals(Object JavaDoc obj)
64     {
65         if (this == obj)
66         {
67             return true;
68         }
69         else if (obj instanceof Identifier)
70         {
71             return m_value == ((Identifier) obj).m_value;
72         }
73         else
74         {
75             return false;
76         }
77     }
78
79     public final int compareTo(Object JavaDoc obj)
80     {
81         if (obj instanceof Identifier)
82         {
83             long diff = getValue() - ((Identifier) obj).getValue();
84
85             return diff > 0 ? 1 : diff < 0 ? -1 : 0;
86         }
87         else
88         {
89             return -1;
90         }
91     }
92
93     public final void writeExternal(ObjectOutput out) throws IOException
94     {
95         out.writeLong(m_value);
96         out.writeBoolean(m_root);
97     }
98
99     public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException JavaDoc
100     {
101         m_value = in.readLong();
102         m_root = in.readBoolean();
103
104         MyOodbManager manager = MyOodbManager.getTheManager();
105         if ((manager != null) && (manager.getStoreManager().isDefraggingDatabase() == true))
106         {
107             java.util.HashMap JavaDoc defragIdMap = manager.getStoreManager().getDefraggedContainerIdentifierMap();
108             Identifier newObjectId = (Identifier) defragIdMap.get(this);
109             m_value = newObjectId.getValue();
110         }
111     }
112
113     public String JavaDoc toString()
114     {
115         return String.valueOf(m_value);
116     }
117 }
118
Popular Tags