Cumulus4j API
(1.0.0)

org.cumulus4j.keymanager.back.shared
Class IdentifierUtil

java.lang.Object
  extended by org.cumulus4j.keymanager.back.shared.IdentifierUtil

public class IdentifierUtil
extends Object

Utility class for identifiers used within Cumulus4j.

Author:
Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de

Constructor Summary
IdentifierUtil()
           
 
Method Summary
static String createRandomID()
           Create a random String identifier with a sufficiently unique length.
static String createRandomID(int length)
           Create a random String identifier with a specified length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IdentifierUtil

public IdentifierUtil()
Method Detail

createRandomID

public static String createRandomID()

Create a random String identifier with a sufficiently unique length.

This method calls createRandomID(int) with a length of 25.

The length of 25 is chosen, because it produces an identifier which has about the same uniqueness as UUID.randomUUID(). This is because the String has 36 ^ 25 (approximately equals 2 ^ 129) possible values while a UUID has 2 ^ 128 possible values and both identifiers are created using the same method (SecureRandom.nextBytes(byte[])).

Returns:
a random String.
See Also:
createRandomID(int)

createRandomID

public static String createRandomID(int length)

Create a random String identifier with a specified length.

The generated identifier will contain only the characters '0'...'9' and 'a'...'z' and will have the specified length. This method uses a SecureRandom (just like UUID.randomUUID()). With a length of 25, the identifier will have about the same uniqueness as a UUID - see createRandomID().

Parameters:
length - the number of chars in the result.
Returns:
a random String with the given length.
See Also:
createRandomID()

Cumulus4j API
(1.0.0)

Copyright © 2012 NightLabs Consulting GmbH. All Rights Reserved.