CommonUtils { public static long[] hexToDualLong(String hexString) { int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " + hexString); } if (length > LONG_HEX_STRING_BYTES * 2) { throw new IllegalArgumentException( "Malformed id(length must be less than 2 times lengh of type long): " + hexString); } int charLast = length - 1; long[] result = new long[2]; result[0] = result[1] = 0; int i = 0; while (charLast >= 0 && i < LONG_BYTES * 2) { result[1] += ((long) Character.digit(hexString.charAt(charLast), 16) & 0xffL) << (4 * i); charLast--; i++; } i = 0; while (charLast >= 0 && i < LONG_BYTES * 2) { result[0] += ((long) Character.digit(hexString.charAt(charLast), 16) & 0xffL) << (4 * i); charLast--; i++; } return result; }  static T parseNum(T num, T defaultInt); static long[] hexToDualLong(String hexString); static long hexToLong(String hexString); static boolean isHexString(String str);  }
@Test public void hexToDualLong() { String traceIdOrig; String traceIdResult; Random rand = new Random(); BigInteger traceIdNum; for (int i = 0; i < 10; i++) { traceIdNum = new BigInteger(125, 100, rand); traceIdOrig = traceIdNum.toString(16); long[] ids = CommonUtils.hexToDualLong(traceIdOrig); traceIdResult = String.format("%x%016x", ids[0], ids[1]); assertEquals(traceIdOrig, traceIdResult); } for (int i = 0; i < 10; i++) { traceIdOrig = TraceIdGenerator.generate(); long[] ids = CommonUtils.hexToDualLong(traceIdOrig); traceIdResult = String.format("%x%016x", ids[0], ids[1]); int diffLen = traceIdOrig.length() - traceIdResult.length(); while (diffLen-- > 0) { traceIdResult = "0" + traceIdResult; } assertEquals(traceIdOrig, traceIdResult); } }