1 package org.sapia.ubik.rmi.server; 2 3 import java.io.Externalizable ; 4 import java.io.IOException ; 5 import java.io.ObjectInput ; 6 import java.io.ObjectOutput ; 7 8 9 20 public class OID implements Externalizable , Comparable { 21 static final long serialVersionUID = 1L; 22 private static final Object _unique = new Object (); 23 private long _id; 24 private int _hashCode; 25 private String _codebase = System.getProperty("java.rmi.server.codebase"); 26 27 28 public OID() { 29 } 30 31 34 public OID(long id) { 35 _id = id; 36 _hashCode = (int) (id ^ (id >>> 32)) ^ _unique.hashCode(); 37 } 38 39 44 public int hashCode() { 45 return _hashCode; 46 } 47 48 52 public boolean equals(Object o) { 53 try { 54 return (((OID) o)._id == _id) && (_hashCode == o.hashCode()); 55 } catch (ClassCastException e) { 56 return false; 57 } 58 } 59 60 63 public void readExternal(ObjectInput in) 64 throws IOException , ClassNotFoundException { 65 _id = in.readLong(); 66 _hashCode = in.readInt(); 67 _codebase =(String )in.readObject(); 68 } 69 70 73 public void writeExternal(ObjectOutput out) throws IOException { 74 out.writeLong(_id); 75 out.writeInt(_hashCode); 76 out.writeObject(_codebase); 77 } 78 79 83 public String getCodebase(){ 84 return _codebase; 85 } 86 87 public String toString() { 88 return new StringBuffer ().append("[id=").append(_id).append(", hashCode=") 89 .append(_hashCode).append("]").toString(); 90 } 91 92 public int compareTo(Object other) { 93 try { 94 long diff = _id - ((OID) other)._id; 95 96 if (diff < 0) { 97 return -1; 98 } else if (diff == 0) { 99 return _hashCode - other.hashCode(); 100 } else { 101 return 1; 102 } 103 } catch (ClassCastException e) { 104 return -1; 105 } 106 } 107 } 108 | Popular Tags |