KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > ObjectID


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: ObjectID.java,v 1.4 2002/08/27 08:32:25 per_nyfelt Exp $
8

9 package org.ozoneDB.core;
10
11 import java.io.*;
12
13 import org.ozoneDB.DxLib.DxCompatible;
14 import org.ozoneDB.DxLib.DxObject;
15
16
17 public class ObjectID extends DxObject implements Externalizable,Comparable JavaDoc {
18
19     final static long serialVersionUID = 2;
20     final static byte subSerialVersionUID = 1;
21
22     private long value = -1;
23
24
25     public ObjectID() {
26     }
27
28     /**
29      * Constructor from a string representation aka a handle.
30      *
31      */

32     public ObjectID(String JavaDoc handle) {
33         value = Long.parseLong(handle);
34     }
35
36     public ObjectID(long v) {
37         value = v;
38     }
39
40     public final long value() {
41         return value;
42     }
43
44
45     public final int hashCode() {
46         //wenn diese 32 bits keinen unterschied mehr bringen,
47
//wird mit equals() weiter verglichen
48
return (int) value;
49     }
50
51
52     public final boolean equals(Object JavaDoc obj) {
53         if (this == obj) {
54             return true;
55         }
56         if (obj != null && obj instanceof ObjectID) {
57             return value == ((ObjectID) obj).value;
58         }
59         return false;
60     }
61
62
63     public final boolean isLess(DxCompatible obj) {
64         if (obj instanceof ObjectID) {
65             return value < ((ObjectID) obj).value;
66         }
67         return false;
68     }
69
70
71     public int compareTo(Object JavaDoc o) {
72         return compareTo((ObjectID) o);
73     }
74
75     /**
76         Compares this ObjectID to the given ObjectID. This is useful for ozone objects which
77         need a sort order but may not be equals. (E.g. for use in a {@link java.util.SortedSet}.)
78
79         @return
80             !=0 for ObjectIDs which are not equal
81             0 for ObjectIDs which are equal
82     */

83     public int comparTo(ObjectID o) {
84         long diff = value()-o.value();
85
86         return diff>0?1:diff<0?-1:0;
87     }
88
89     public Object JavaDoc clone() {
90         return new ObjectID(value);
91     }
92
93
94     public final void writeExternal(ObjectOutput out) throws IOException {
95         // env.logWriter.newEntry ("write: " + getClass().toString() + " " + value, LogWriter.DEBUG);
96
out.writeByte(subSerialVersionUID);
97         out.writeLong(value);
98     }
99
100
101     public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException JavaDoc {
102         byte streamVersionUID = in.readByte();
103         value = in.readLong();
104         // env.logWriter.newEntry ("read: " + getClass().toString() + " " + value, LogWriter.DEBUG);
105
}
106
107
108     /**
109      * The value of the ObjectID as String. Do not change this, the name
110      * of the cluster files depend on it.
111      */

112     public String JavaDoc toString() {
113         return String.valueOf(value);
114     }
115 }
116
Popular Tags