1 22 package org.jboss.util.id; 23 24 46 public class GUID 47 implements ID, Comparable 48 { 49 50 static final long serialVersionUID = 3289509836244263718L; 51 52 protected final VMID vmid; 53 54 55 protected final UID uid; 56 57 58 protected final int hashCode; 59 60 63 public GUID() { 64 this.vmid = VMID.getInstance(); 65 this.uid = new UID(); 66 67 int code = vmid.hashCode(); 69 code ^= uid.hashCode(); 70 hashCode = code; 71 } 72 73 78 protected GUID(final GUID guid) { 79 this.vmid = guid.vmid; 80 this.uid = guid.uid; 81 this.hashCode = guid.hashCode; 82 } 83 84 89 public final VMID getVMID() { 90 return vmid; 91 } 92 93 98 public final UID getUID() { 99 return uid; 100 } 101 102 107 public String toString() { 108 return vmid.toString() + "-" + uid.toString(); 109 } 110 111 116 public int hashCode() { 117 return hashCode; 118 } 119 120 129 public boolean equals(final Object obj) { 130 if (obj == this) return true; 131 132 if (obj != null && obj.getClass() == getClass()) { 133 GUID guid = (GUID)obj; 134 135 return 136 guid.vmid.equals(vmid) && 137 guid.uid.equals(uid); 138 } 139 140 return false; 141 } 142 143 148 public Object clone() { 149 try { 150 return super.clone(); 151 } 152 catch (CloneNotSupportedException e) { 153 throw new InternalError (); 154 } 155 } 156 157 162 public static String asString() { 163 return new GUID().toString(); 164 } 165 166 public int compareTo(Object o) 167 { 168 GUID guid = (GUID)o; 169 return this.toString().compareTo(guid.toString()); 170 } 171 172 } 173 | Popular Tags |