1 34 package org.dspace.app.didl; 35 36 import java.io.Serializable ; 37 48 public final class UUID implements Serializable 49 { 50 private long hi; 51 private long lo; 52 53 59 public UUID(UUID uuid) 60 { 61 this.hi = uuid.hi; 62 this.lo = uuid.lo; 63 } 64 65 76 public UUID(long _hi, long _lo) 77 { 78 this.hi = _hi; 79 this.lo = _lo; 80 lo &= 0x3FFFFFFFFFFFFFFFL; lo |= 0x8000000000000000L; 82 lo |= 0x0000800000000000L; 85 hi &= 0xFFFFFFFFFFFF0FFFL; hi |= 0x0000000000004000L; 87 } 88 89 97 public boolean equals(Object obj) 98 { 99 if(this == obj) return true; 101 if(obj instanceof UUID) 102 return equals((UUID)obj); 103 return false; 104 } 105 106 114 public boolean equals(UUID uuid) 115 { 116 return (hi == uuid.hi && lo == uuid.lo); 117 } 118 119 120 126 public int hashCode() 127 { 128 return new Long (hi ^ lo).hashCode(); 129 } 130 131 132 138 public String toString() 139 { 140 return ( 141 hexDigits(hi >> 32, 4) + "-" + 143 hexDigits(hi >> 16, 2) + "-" + 145 hexDigits(hi, 2) + "-" + 147 hexDigits(lo >> 48, 2) + "-" + 149 hexDigits(lo, 6)); } 151 152 165 private static String hexDigits(long lVal, int nHexOctets) { 166 long tmp = 1L << (nHexOctets * 2 * 4); long result = lVal & (tmp - 1); result = tmp | result; return Long.toHexString(result).substring(1); } 171 } | Popular Tags |