com.ninja_squad.dbsetup.generator
Class StringSequenceValueGenerator

java.lang.Object
  extended by com.ninja_squad.dbsetup.generator.StringSequenceValueGenerator
All Implemented Interfaces:
ValueGenerator<java.lang.String>

public final class StringSequenceValueGenerator
extends java.lang.Object
implements ValueGenerator<java.lang.String>

A ValueGenerator that returns a string prefix followed by a sequence number, optionally left-padded with 0 to ensure a correct ordering (for example: CODE_001, CODE_002, etc.). Instances of this generator are created by ValueGenerators.stringSequence(String).


Method Summary
 StringSequenceValueGenerator incrementingBy(int increment)
          Increments the number by the given increment.
 java.lang.String nextValue()
          Called each time a new row is inserted, to get the value to insert in the column using this value generator.
 StringSequenceValueGenerator startingAt(long start)
          Restarts the sequence at the given value
 java.lang.String toString()
           
 StringSequenceValueGenerator withLeftPadding(int paddedNumberLength)
          Tells the generator to left-pad the number it generates with 0 until the length of the number is the given length.
 StringSequenceValueGenerator withoutLeftPadding()
          Tells the generator to avoid left-padding the number it generates with 0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

withLeftPadding

public StringSequenceValueGenerator withLeftPadding(int paddedNumberLength)
Tells the generator to left-pad the number it generates with 0 until the length of the number is the given length. For example, passing 3 to this method will generate numbers 001, 002, 003, 004, etc. If the generated number, before padding, has a length already equal or larger that the given length, the number is not padded.

Parameters:
paddedNumberLength - the length of the number once padded. Must be > 0.
Returns:
this instance, for chaining

withoutLeftPadding

public StringSequenceValueGenerator withoutLeftPadding()
Tells the generator to avoid left-padding the number it generates with 0

Returns:
this instance, for chaining

startingAt

public StringSequenceValueGenerator startingAt(long start)
Restarts the sequence at the given value

Parameters:
start - the new starting value of the sequence
Returns:
this instance, for chaining

incrementingBy

public StringSequenceValueGenerator incrementingBy(int increment)
Increments the number by the given increment.

Returns:
this instance, for chaining

nextValue

public java.lang.String nextValue()
Description copied from interface: ValueGenerator
Called each time a new row is inserted, to get the value to insert in the column using this value generator.

Specified by:
nextValue in interface ValueGenerator<java.lang.String>
Returns:
the value to insert in the column associated with this generator.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object