Commons Id is a component used to generate identifiers. Several identifier-generation algorithms are supported by Generators included with the package. The framework is extensible to support additional implementations.
A utility class, IdentifierUtils,
provides access to singleton generators and
methods to generate identifiers without explicitly creating a Generator.
For example, to generate a sequence of Alphanumeric identifiers, starting with ""000000000000001" and increasing sequentially, you can just repeatedly call
IdentifierUtils.nextStringAlphanumericIdentifier();
IdentifierUtils
class, exposed publicly as
IdentifierUtils.STRING_ALPHANUMERIC_IDENTIFIER_GENERATOR.
The Generator implementation (like all others in this package) is synchronized.
You can also create Generators explicitly using the IdentifierGeneratorFactory
abstract factory class. To get an Identifier Generator instance, first get a concrete
factory and then use the appropriate instance creation method:
IdentifierGeneratorFactory factory = IdentifierGeneratorFactory.newInstance(); StringIdentifierGenerator generator = factory.alphanumericGenerator();
String id = generator.nextStringIdentifier();
Generator | Description |
---|---|
AlphanumericGenerator | Generates an incrementing number in base 36 as a String object |
NumericGenerator | Generates an incrementing decimal number as a String object |
LongGenerator | Generates an incrementing number as a Long object |
SessionIdGenerator | Generates an alphanumeric 10+ character identifier with a random component. The exact length depends on the number of ids requested per time period. |
UUID Generators | Generates universally Unique Identifiers based on the IETF Draft Uuid Specification. |
The JavaDoc API documents are available online.