/**
 * Copyright 2011-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.informantproject.core.trace;

import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * The unique identifier for a trace. The string representation of the unique identifier is lazily
 * constructed since it is not needed in the majority of the cases (it is only needed for traces
 * which are either persisted and/or viewed in-flight).
 * 
 * @author Trask Stalnaker
 * @since 0.5
 */
class TraceUniqueId {

    // used to populate id (below)
    private static final AtomicInteger idCounter = new AtomicInteger();

    private final long startTimeMillis;
    private final int id;

    TraceUniqueId(long startTimeMillis) {
        this.startTimeMillis = startTimeMillis;
        id = idCounter.getAndIncrement();
    }

    public String get() {
        return startTimeMillis + "-" + BigInteger.valueOf(id).toString(16);
    }
}

@@ -681,16 +681,39 @@
 nteger;%0A
+import java.util.Date;%0A
 import j
@@ -745,23 +745,60 @@
 c.Atomic
-Integer
+Long;%0A%0Aimport com.google.common.base.Strings
 ;%0A%0A/**%0A 
@@ -1186,23 +1186,20 @@
 l Atomic
-Integer
+Long
  idCount
@@ -1217,18 +1217,110 @@
 omic
-Integer();
+Long();%0A%0A    private static final long MAX_ID = (long) Math.pow(16, 6); // at most 6 bytes in hex form
 %0A%0A  
@@ -1379,11 +1379,12 @@
 nal 
-int
+long
  id;
@@ -1565,16 +1565,31 @@
  return 
+twelveDigitHex(
 startTim
@@ -1599,51 +1599,826 @@
 llis
+)
  + 
-%22-%22 + BigInteger.valueOf(id).toString(16
+BigInteger.valueOf(id %25 MAX_ID).toString(16);%0A    %7D%0A%0A    private static String twelveDigitHex(long x) %7B%0A        String s = BigInteger.valueOf(x).toString(16);%0A        if (s.length() %3E 12) %7B%0A            return s.substring(s.length() - 12);%0A        %7D else if (s.length() == 12) %7B%0A            return s;%0A        %7D else if (s.length() == 11) %7B%0A            // this is the case for dates between Nov 3, 2004 and Jun 23, 2527 so it seems worth%0A            // optimizing%0A            return '0' + s;%0A        %7D else %7B%0A            return Strings.padStart(s, 12, '0');%0A        %7D%0A    %7D%0A%0A    public static void main(String... args) %7B%0A        System.out.println(twelveDigitHex(System.currentTimeMillis()));%0A        System.out.println(new Date((long) Math.pow(16, 10)));%0A        System.out.println(new Date((long) Math.pow(16, 11))
 );%0A 

Improve the look of the trace id