KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > uuid > UuidUtilPadded


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * UuidUtilPadded.java
26  *
27  * Created on May 26, 2005, 11:15 AM
28  */

29
30 package com.sun.enterprise.util.uuid;
31
32 /**
33  *
34  * @author lwhite
35  */

36 public class UuidUtilPadded extends UuidUtil {
37     
38     static final int DESIRED_UUID_LENGTH = 40;
39     
40     //this method can take in the session object
41
//and insure better uniqueness guarantees
42
//needed length must be greater than not less than
43
//expected returned lengths - i.e. at least 40
44
public static String JavaDoc generateUuid(Object JavaDoc obj, int inputLength) {
45         int desiredLength =
46             DESIRED_UUID_LENGTH >= inputLength ? DESIRED_UUID_LENGTH:inputLength;
47         String JavaDoc unpaddedUuid = UuidUtil.generateUuid(obj);
48         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(unpaddedUuid);
49         int neededPadding = desiredLength - unpaddedUuid.length();
50         //int neededPadding = DESIRED_UUID_LENGTH - unpaddedUuid.length();
51
if(neededPadding > 0) {
52             for(int i=0; i<neededPadding; i++) {
53                 sb.append("F");
54             }
55         }
56         return sb.toString();
57     }
58     
59     /**
60      * Method main
61      *
62      *
63      * @param args
64      *
65      * @audience
66      */

67     public static void main(String JavaDoc[] args) {
68         System.out.println(UuidUtilPadded.generateUuidMM());
69         System.out.println(UuidUtilPadded.generateUuid());
70         System.out.println(UuidUtilPadded.generateUuid(new Object JavaDoc()));
71         System.out.println(UuidUtilPadded.generateUuid(new Object JavaDoc(), 40));
72     }
73     
74 }
75
Popular Tags