1 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 { 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 32 public ObjectID(String 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 return (int) value; 49 } 50 51 52 public final boolean equals(Object 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 o) { 72 return compareTo((ObjectID) o); 73 } 74 75 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 clone() { 90 return new ObjectID(value); 91 } 92 93 94 public final void writeExternal(ObjectOutput out) throws IOException { 95 out.writeByte(subSerialVersionUID); 97 out.writeLong(value); 98 } 99 100 101 public final void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 102 byte streamVersionUID = in.readByte(); 103 value = in.readLong(); 104 } 106 107 108 112 public String toString() { 113 return String.valueOf(value); 114 } 115 } 116 | Popular Tags |