org.apache.commons.id
Class ConstantIdentifierGenerator

java.lang.Object
  extended by org.apache.commons.id.AbstractStringIdentifierGenerator
      extended by org.apache.commons.id.ConstantIdentifierGenerator
All Implemented Interfaces:
IdentifierGenerator, StringIdentifierGenerator

public class ConstantIdentifierGenerator
extends AbstractStringIdentifierGenerator

StringIdentifierGenerator that always returns the same string. Use with CompositeIdentifierGenerator to embed constant string identifiers, or to add prefixes or suffixes.

Null constant values are not allowed. The default (assumed by the argumentless constructor) is an empty string.

Version:
$Id$
Author:
Commons-Id team

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
ConstantIdentifierGenerator()
          Creates a new ConstantIdentifierGenerator using the default (empty string) constant value.
ConstantIdentifierGenerator(java.lang.String identifier)
          Creates a new ConstantIdentifierGenerator using the given constant value.
 
Method Summary
static StringIdentifierGenerator getInstance(java.lang.String identifier)
          Factory method to create a new ConstantIdentifierGenerator with the given constant value.
 long maxLength()
          Returns the length of the constant string returned by this generator.
 long minLength()
          Returns the length of the constant string returned by this generator.
 java.lang.String nextStringIdentifier()
          Gets the next identifier in the sequence.
 
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

ConstantIdentifierGenerator

public ConstantIdentifierGenerator()
Creates a new ConstantIdentifierGenerator using the default (empty string) constant value.


ConstantIdentifierGenerator

public ConstantIdentifierGenerator(java.lang.String identifier)
Creates a new ConstantIdentifierGenerator using the given constant value.

Null constant values are not allowed.

Parameters:
identifier - constant value returned by the generator. Must not be null.
Throws:
IllegalArgumentExeption - if identifier is null
Method Detail

getInstance

public static StringIdentifierGenerator getInstance(java.lang.String identifier)
Factory method to create a new ConstantIdentifierGenerator with the given constant value. Does not allow null values.

Parameters:
identifier - constant value returned by the newly created generator. Must not be null.
Returns:
a new ConstantIdentifierGenerator
Throws:
java.lang.IllegalArgumentException - if identifier is null

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

maxLength

public long maxLength()
Returns the length of the constant string returned by this generator. If the constant is null or an empty string, 0 is returned.

Specified by:
maxLength in interface StringIdentifierGenerator
Overrides:
maxLength in class AbstractStringIdentifierGenerator
Returns:
the length of the constant string returned by this generator

minLength

public long minLength()
Returns the length of the constant string returned by this generator. If the constant is null or an empty string, 0 is returned.

Specified by:
minLength in interface StringIdentifierGenerator
Overrides:
minLength in class AbstractStringIdentifierGenerator
Returns:
the length of the constant string returned by this generator


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