org.apache.commons.id
Class CompositeIdentifierGenerator

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

public class CompositeIdentifierGenerator
extends AbstractStringIdentifierGenerator
implements java.io.Serializable

Identifier generator that concatenates the results of a list of string identifier generators.

Since:
1.0
Version:
$Revision$ $Date$
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
CompositeIdentifierGenerator(StringIdentifierGenerator[] identifierGenerators)
          Constructor that does not check for nulls.
 
Method Summary
 StringIdentifierGenerator[] getIdentifierGenerators()
          Returns a (shallow) copy of the array of identifier generators concatenated by this generator.
static StringIdentifierGenerator getInstance(java.util.Collection generators)
          Create a new CompositeIdentifierGenerator that concatenates the results of the provided collection of generators.
static StringIdentifierGenerator getInstance(StringIdentifierGenerator[] generators)
          Factory method to create a new CompositeIdentifierGenerator from an input array of StringIdentifierGenerator instances.
 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.AbstractStringIdentifierGenerator
nextIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeIdentifierGenerator

public CompositeIdentifierGenerator(StringIdentifierGenerator[] identifierGenerators)
Constructor that does not check for nulls. Use getInstance(StringIdentifierGenerator[]) to validate the input array.

Parameters:
identifierGenerators - the identifier generators to concatenate
Method Detail

getInstance

public static StringIdentifierGenerator getInstance(StringIdentifierGenerator[] generators)
Factory method to create a new CompositeIdentifierGenerator from an input array of StringIdentifierGenerator instances.

The input array is (shallow) copied - i.e., the object references in the input array are copied into a new array used internally. The array is expected to be non-empty and not to contain nulls.

Parameters:
generators - the identifiers to concatenate, copied by reference
Returns:
the composite identifier generator
Throws:
java.lang.IllegalArgumentException - if the generators array is null
java.lang.IllegalArgumentException - if any generator in the array is null

getInstance

public static StringIdentifierGenerator getInstance(java.util.Collection generators)
Create a new CompositeIdentifierGenerator that concatenates the results of the provided collection of generators. Order is determined by the iterator() method on the collection.

Parameters:
generators - a collection of string identifier generators to concatenate
Returns:
the composite identifier generator
Throws:
java.lang.IllegalArgumentException - if the generators collection is null, empty, or contains nulls

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()
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

getIdentifierGenerators

public StringIdentifierGenerator[] getIdentifierGenerators()
Returns a (shallow) copy of the array of identifier generators concatenated by this generator.

Returns:
the identifier generators


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