01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: UniqueID.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: public class UniqueID {
11: private byte[] mID = null;
12: private String mIDString = null;
13:
14: UniqueID(byte[] id) {
15: setID(id);
16: }
17:
18: public byte[] getID() {
19: return mID;
20: }
21:
22: void setID(byte[] id) {
23: this .mID = id;
24: mIDString = null;
25: }
26:
27: public String toString() {
28: if (null == mIDString) {
29: StringBuilder string_id = new StringBuilder();
30: String hexadecimal = null;
31: int byterange = Math.abs(Byte.MAX_VALUE)
32: + Math.abs(Byte.MIN_VALUE) + 1;
33: int maxhexdigitsperbyte = (Integer
34: .toHexString(byterange - 1)).length();
35: for (int decimal : mID) {
36: if (decimal < 0) {
37: decimal = byterange + decimal;
38: }
39:
40: hexadecimal = Integer.toHexString(decimal);
41: for (int j = hexadecimal.length(); j < maxhexdigitsperbyte; j++) {
42: string_id.append('0');
43: }
44: string_id.append(hexadecimal);
45: }
46: mIDString = string_id.toString();
47: }
48:
49: return mIDString;
50: }
51: }
|