1 10 11 package com.triactive.jdo.store; 12 13 14 36 37 public final class OID implements java.io.Serializable 38 { 39 43 public static final long MAX_VALUE = 0xfffffffffffffffL; 44 45 48 public static final int MAX_CLASSID = 0x7fff; 49 50 54 public static final int MAX_OBJIDHI = 0x3fffffff; 55 56 60 public static final int MAX_OBJIDLO = 0x7fff; 61 62 65 public static final int MAX_LENGTH = 14; 66 67 68 71 private long value; 72 73 74 82 83 public OID(long value) throws IllegalArgumentException 84 { 85 if (value < 0 || value > MAX_VALUE) 86 throw new IllegalArgumentException ("Invalid OID value: " + value); 87 88 this.value = value; 89 } 90 91 92 104 105 public OID(int classID, int objIDHi, int objIDLo) throws IllegalArgumentException 106 { 107 if (classID < 0 || classID > MAX_CLASSID) 108 throw new IllegalArgumentException ("Invalid class ID value: " + classID); 109 110 if (objIDHi < 0 || objIDHi > MAX_OBJIDHI) 111 throw new IllegalArgumentException ("Invalid object ID hi value: " + objIDHi); 112 113 if (objIDLo < 0 || objIDLo > MAX_OBJIDLO) 114 throw new IllegalArgumentException ("Invalid object ID lo value: " + objIDLo); 115 116 value = ((long)classID << 45) | ((long)objIDHi << 15) | objIDLo; 117 } 118 119 120 130 131 public OID(String s) throws IllegalArgumentException 132 { 133 if (s.length() != 14 || s.charAt(3) != '-' || s.charAt(10) != '-') 134 throw new IllegalArgumentException ("Invalid OID string value: " + s); 135 136 StringBuffer buf = new StringBuffer (s); 137 138 buf.deleteCharAt(10).deleteCharAt(3); 139 140 value = Long.parseLong(buf.toString(), 32); 141 142 if (value < 0 || value > MAX_VALUE) 143 throw new IllegalArgumentException ("Invalid OID string value: " + s); 144 } 145 146 147 152 153 public int getClassID() 154 { 155 return (int)(value >> 45); 156 } 157 158 159 164 165 public long longValue() 166 { 167 return value; 168 } 169 170 171 public boolean equals(Object obj) 172 { 173 if (obj == this) 174 return true; 175 176 if (!(obj instanceof OID)) 177 return false; 178 179 return (value == ((OID)obj).value); 180 } 181 182 183 public int hashCode() 184 { 185 return (int)(value ^ (value >> 32)); 186 } 187 188 189 200 201 public String toString() 202 { 203 StringBuffer s = new StringBuffer ("00000000000").append(Long.toString(value, 32)); 204 205 s.delete(0, s.length() - 12).insert(3, '-').insert(10, '-'); 206 207 return s.toString(); 208 } 209 } 210 | Popular Tags |