1 24 package org.objectweb.jalisto.se.impl; 25 26 import java.io.Serializable ; 27 28 32 public class LogicalOid implements Serializable , Comparable { 33 public LogicalOid(long floidAsLong) { 34 this.floidAsLong = floidAsLong; 35 } 36 37 public LogicalOid(String floidAsString) { 38 int index = floidAsString.indexOf("."); 39 int clid = Integer.parseInt(floidAsString.substring(0, index)); 40 long instanceNumber = Long.parseLong(floidAsString.substring(index + 1)); 41 this.floidAsLong = clid * classMulti + instanceNumber; 42 } 43 44 public LogicalOid getClone() { 45 return new LogicalOid(floidAsLong); 46 } 47 48 public long getFloidAsLong() { 49 return floidAsLong; 50 } 51 52 public String getFloidAsString() { 53 return Long.toString(floidAsLong); 54 } 55 56 public short getClid() { 57 return (short) (floidAsLong / classMulti); 58 } 59 60 public long getInstanceNumber() { 61 return floidAsLong % classMulti; 62 } 63 64 public int compareTo(Object o) { 65 LogicalOid candidate = (LogicalOid) o; 66 67 if (this.floidAsLong < candidate.floidAsLong) { 68 return -1; 69 } else if (this.floidAsLong > candidate.floidAsLong) { 70 return 1; 71 } else { 72 return 0; 73 } 74 } 75 76 public boolean equals(Object obj) { 77 try { 78 return ((LogicalOid) obj).floidAsLong == this.floidAsLong; 79 } catch (ClassCastException e) { 80 } 81 return false; 82 } 83 84 public int hashCode() { 85 return (int) (floidAsLong ^ (floidAsLong >>> 32)); 86 } 87 88 public String toString() { 89 return getClid() + "." + getInstanceNumber(); 90 } 91 92 private long floidAsLong; 93 94 static final long serialVersionUID = -7589377069041161459L; 95 public static final long classMulti = 1000000000000000L; 96 } 97 | Popular Tags |