public class CodeGenerator
extends java.lang.Object
After the class instance is created, the invoker needs to explicitly call the validateCodePattern method to do initial code pattern parse and validation.
The code generation batch size is needed before the code generation starts.
The class has a default Pattern registry. The default Pattern classes are SequencePattern, NumericPattern, AlphaUpperNumericPattern, AlphaLowerNumericPattern, AlphaMixNumericPattern, AlphabeticUpperPattern, AlphabeticLowerPattern and AlphabeticMixPattern.
If there needs a new Pattern to register, user must following the steps to make the pattern work properly:
Constructor and Description |
---|
CodeGenerator(java.lang.String pattern, java.lang.Long target)
Construct the code generator
|
Modifier and Type | Method and Description |
---|---|
void | checkCodespaceSize(java.lang.Long targetGenerated)
This method validates the code space size.
|
static void | cleanCodeGeneratorForPromotion(java.lang.String promotionId)
Clean the related code generator free for GC
|
java.lang.String[] | generateNextBatch()
This method generates a batch of codes.
|
int | getBatchSize()
This method gets the batch size.
|
static CodeGenerator | getCodeGeneratorForPromotion(java.lang.String promotionId)
Get the promotionId related code generator
|
java.math.BigDecimal | getCodeSpace()
This method calculates the code pattern space according to the list of parsed Pattern objects.
|
long | getErrorCodesSize()
Get the error codes size.
|
java.lang.Long | getTargetTotal()
This method gets the total number of the generated codes
|
java.util.List<java.lang.String> | patternStyleConverter(java.lang.String segment)
This method divides the input string into a list of pattern segments and convert the segments into the Pattern objects.
|
void | registerPattern(Pattern p)
This method registers an extra Pattern.
|
void | setBatchSize(int localBatchSize)
This method sets the batch size.
|
static void | setCodeGeneratorForPromotion(java.lang.String promotionId, CodeGenerator cg)
Put the code generator to cache
|
void | setCodePattern(java.lang.String pattern)
This method sets the code pattern definition string.
|
void | setErrorCodesSize(long size)
Set the error codes size.
|
void | setFinishedSize(long aFinishedSize)
This method sets the total number of generate codes
|
void | setTargetTotal(java.lang.Long target)
This method sets the total number of generate codes
|
void | validateCodePattern()
This method parses the pattern string and checks if code space size is enough for the total number of generated codes.
|
public CodeGenerator(java.lang.String pattern, java.lang.Long target)
public static CodeGenerator getCodeGeneratorForPromotion(java.lang.String promotionId)
public static void setCodeGeneratorForPromotion(java.lang.String promotionId, CodeGenerator cg)
public static void cleanCodeGeneratorForPromotion(java.lang.String promotionId)
public void setCodePattern(java.lang.String pattern)
public void setFinishedSize(long aFinishedSize)
public void setTargetTotal(java.lang.Long target)
public java.lang.Long getTargetTotal()
public void registerPattern(Pattern p)
This method allows another Pattern to register into this code generator.
public java.util.List<java.lang.String> patternStyleConverter(java.lang.String segment)
public void checkCodespaceSize(java.lang.Long targetGenerated) throws PatternDefineException
If the code space size is not enough, it will directly throw the PatternDefineException
public void validateCodePattern() throws PatternDefineException
public java.math.BigDecimal getCodeSpace()
public java.lang.String[] generateNextBatch()
public int getBatchSize()
public void setBatchSize(int localBatchSize)
public void setErrorCodesSize(long size)
public long getErrorCodesSize()