org.apache.commons.id.serial
Class PrefixedNumericGenerator

java.lang.Object
  extended by org.apache.commons.id.AbstractStringIdentifierGenerator
      extended by org.apache.commons.id.serial.NumericGenerator
          extended by org.apache.commons.id.serial.PrefixedNumericGenerator
All Implemented Interfaces:
java.io.Serializable, IdentifierGenerator, StringIdentifierGenerator

public class PrefixedNumericGenerator
extends NumericGenerator

PrefixedNumericGenerator is an Identifier Generator that generates an incrementing number with a prefix as a String object.

If the wrap argument passed to the constructor is set to true, the sequence will wrap, returning negative values when Long.MAX_VALUE reached; otherwise an IllegalStateException will be thrown.

Version:
$Id$
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
PrefixedNumericGenerator(java.lang.String prefix, boolean wrap, long initialValue)
          Create a new prefixed numeric generator with the specified prefix.
 
Method Summary
 java.lang.String getPrefix()
          Return the prefix for this prefixed numeric generator.
 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.
 
Methods inherited from class org.apache.commons.id.serial.NumericGenerator
isWrap, setWrap
 
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

PrefixedNumericGenerator

public PrefixedNumericGenerator(java.lang.String prefix,
                                boolean wrap,
                                long initialValue)
Create a new prefixed numeric generator with the specified prefix.

Parameters:
prefix - prefix, must not be null
wrap - should the factory wrap when it reaches the maximum long value (or throw an exception)
initialValue - the initial long value to start at
Throws:
java.lang.NullPointerException - if prefix is null
Method Detail

getPrefix

public java.lang.String getPrefix()
Return the prefix for this prefixed numeric generator.

Returns:
the prefix for this prefixed numeric generator

maxLength

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

The maximum value is determined from the length of the string representation of Long.MAX_VALUE.

Specified by:
maxLength in interface StringIdentifierGenerator
Overrides:
maxLength in class NumericGenerator
Returns:
the maximum identifier length

minLength

public long minLength()
Description copied from class: NumericGenerator

Returns the minimum length (number of characters) for an identifier from this sequence.

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

nextStringIdentifier

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

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


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