org.apache.commons.id.serial
Class NumericGenerator

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

public class NumericGenerator
extends AbstractStringIdentifierGenerator
implements java.io.Serializable

NumericIdentifierGenerator is an Identifier Generator that generates an incrementing number 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: NumericGenerator.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
NumericGenerator(boolean wrap, long initialValue)
          Constructor.
 
Method Summary
 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

NumericGenerator

public NumericGenerator(boolean wrap,
                        long initialValue)

Constructor.

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

maxLength

public long maxLength()
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 AbstractStringIdentifierGenerator
Returns:
the maximum identifier length

minLength

public long minLength()

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

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

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

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.