1 23 24 29 30 package com.sun.enterprise.util.uuid; 31 32 36 public class UuidUtilPadded extends UuidUtil { 37 38 static final int DESIRED_UUID_LENGTH = 40; 39 40 public static String generateUuid(Object obj, int inputLength) { 45 int desiredLength = 46 DESIRED_UUID_LENGTH >= inputLength ? DESIRED_UUID_LENGTH:inputLength; 47 String unpaddedUuid = UuidUtil.generateUuid(obj); 48 StringBuffer sb = new StringBuffer (unpaddedUuid); 49 int neededPadding = desiredLength - unpaddedUuid.length(); 50 if(neededPadding > 0) { 52 for(int i=0; i<neededPadding; i++) { 53 sb.append("F"); 54 } 55 } 56 return sb.toString(); 57 } 58 59 67 public static void main(String [] args) { 68 System.out.println(UuidUtilPadded.generateUuidMM()); 69 System.out.println(UuidUtilPadded.generateUuid()); 70 System.out.println(UuidUtilPadded.generateUuid(new Object ())); 71 System.out.println(UuidUtilPadded.generateUuid(new Object (), 40)); 72 } 73 74 } 75 | Popular Tags |