1 package com.espada.bugtracker.util; 2 3 import java.io.PrintStream ; 4 import java.util.Random ; 5 6 public class GenerateUniqueId 7 { 8 9 public static synchronized String getIdentifier() 10 { 11 StringBuffer stringbuffer = new StringBuffer (); 12 long l = randomSource.nextLong(); 13 if(l < 0L) 14 l = -l; 15 l %= 0x81bf1000L; 16 l += 0x81bf1000L; 17 stringbuffer.append(Long.toString(l, 36).substring(1)); 18 long l1 = System.currentTimeMillis() / 2000L; 19 l1 %= 46656L; 20 l1 += 46656L; 21 stringbuffer.append(Long.toString(l1, 36).substring(1)); 22 if(lastTimeVal != l1) 23 { 24 lastTimeVal = l1; 25 session_count = 0; 26 } 27 stringbuffer.append(Long.toString(++session_count, 36)); 28 return stringbuffer.toString(); 29 } 30 31 public synchronized String getIdentifier(String s) 32 { 33 if(s != null && s.length() > 0) 34 return getIdentifier() + "." + s; 35 else 36 return getIdentifier(); 37 } 38 39 public static void main(String args[]) 40 { 41 System.out.println(getIdentifier()); 42 System.out.println(getIdentifier()); 43 System.out.println(getIdentifier()); 44 System.out.println(getIdentifier()); 45 } 46 47 public GenerateUniqueId() 48 { 49 } 50 51 private static int session_count = 0; 52 private static long lastTimeVal = 0L; 53 private static Random randomSource = new Random (); 54 public static final long maxRandomLen = 0x81bf1000L; 55 public static final long maxSessionLifespanTics = 46656L; 56 public static final long ticDifference = 2000L; 57 58 } 59 | Popular Tags |