org.apache.commons.id.serial
Class AlphanumericGenerator

java.lang.Object
  extended by org.apache.commons.id.AbstractStringIdentifierGenerator
      extended by org.apache.commons.id.serial.AlphanumericGenerator
All Implemented Interfaces:
java.io.Serializable, IdentifierGenerator, StringIdentifierGenerator
Direct Known Subclasses:
PrefixedAlphanumericGenerator

public class AlphanumericGenerator
extends AbstractStringIdentifierGenerator
implements java.io.Serializable

AlphanumericGenerator is an identifier generator that generates an incrementing number in base 36 as a String object.

All generated ids have the same length (padding with 0's on the left), which is determined by the size parameter passed to the constructor.

The wrap property determines whether or not the sequence wraps when it reaches the largest value that can be represented in size base 36 digits. If wrap is false and the the maximum representable value is exceeded, an IllegalStateException is thrown

Version:
$Id: AlphanumericGenerator.java 480488 2006-11-29 08:57:26Z bayard $
Author:
Commons-Id team
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.commons.id.AbstractStringIdentifierGenerator
ALPHA_NUMERIC_CHARSET_SIZE, DEFAULT_ALPHANUMERIC_IDENTIFIER_SIZE, MAX_INT_ALPHANUMERIC_VALUE_LENGTH, MAX_INT_NUMERIC_VALUE_LENGTH, MAX_LONG_ALPHANUMERIC_VALUE_LENGTH, MAX_LONG_NUMERIC_VALUE_LENGTH
 
Fields inherited from interface org.apache.commons.id.StringIdentifierGenerator
INFINITE_MAX_LENGTH
 
Constructor Summary
AlphanumericGenerator(boolean wrap)
          Constructor with a default size for the alphanumeric identifier.
AlphanumericGenerator(boolean wrap, int size)
          Constructor.
AlphanumericGenerator(boolean wrap, java.lang.String initialValue)
          Construct with a counter, that will start at the specified alphanumeric value.
 
Method Summary
 int getSize()
          Returns the (constant) size of the strings generated by this generator.
 boolean isWrap()
          Getter for property wrap.
 long maxLength()
          Returns the maximum length (number or characters) for an identifier from this sequence.
 long minLength()
          Returns the minimum length (number of characters) for an identifier from this sequence.
 java.lang.String nextStringIdentifier()
          Gets the next identifier in the sequence.
 void setWrap(boolean wrap)
          Sets the wrap property.
 
Methods inherited from class org.apache.commons.id.AbstractStringIdentifierGenerator
nextIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlphanumericGenerator

public AlphanumericGenerator(boolean wrap)
Constructor with a default size for the alphanumeric identifier.

Parameters:
wrap - should the factory wrap when it reaches the maximum long value (or throw an exception)

AlphanumericGenerator

public AlphanumericGenerator(boolean wrap,
                             int size)
Constructor.

Parameters:
wrap - should the factory wrap when it reaches the maximum long value (or throw an exception)
size - the size of the identifier

AlphanumericGenerator

public AlphanumericGenerator(boolean wrap,
                             java.lang.String initialValue)
Construct with a counter, that will start at the specified alphanumeric value.

Parameters:
wrap - should the factory wrap when it reaches the maximum value (or throw an exception)
initialValue - the initial value to start at
Method Detail

maxLength

public long maxLength()
Description copied from class: AbstractStringIdentifierGenerator
Returns the maximum length (number or characters) for an identifier from this sequence.

The default implementation returns StringIdentifierGenerator.INFINITE_MAX_LENGTH. Implementations with bounded length identifiers should override this method to return the maximum length of a generated identifier.

Specified by:
maxLength in interface StringIdentifierGenerator
Overrides:
maxLength in class AbstractStringIdentifierGenerator
Returns:
the maximum identifier length, or StringIdentifierGenerator.INFINITE_MAX_LENGTH if there is no upper bound

minLength

public long minLength()
Description copied from class: AbstractStringIdentifierGenerator
Returns the minimum length (number of characters) for an identifier from this sequence.

The default implementation returns 0. Implementations with identifiers having a postive minimum length should override this method to return the maximum length of a generated identifier.

Specified by:
minLength in interface StringIdentifierGenerator
Overrides:
minLength in class AbstractStringIdentifierGenerator
Returns:
the minimum identifier length

isWrap

public boolean isWrap()
Getter for property wrap.

Returns:
true if this generator is set up to wrap.

setWrap

public void setWrap(boolean wrap)
Sets the wrap property.

Parameters:
wrap - value for the wrap property

getSize

public int getSize()
Returns the (constant) size of the strings generated by this generator.

Returns:
the size of generated identifiers

nextStringIdentifier

public java.lang.String nextStringIdentifier()
Description copied from interface: StringIdentifierGenerator
Gets the next identifier in the sequence.

Specified by:
nextStringIdentifier in interface StringIdentifierGenerator
Specified by:
nextStringIdentifier in class AbstractStringIdentifierGenerator
Returns:
the next String identifier in sequence


Copyright 2003-2008 The Apache Software Foundation. All Rights Reserved.