com.ibm.commerce.promotion.uniquecode.generator

Class SequencePattern

  • java.lang.Object
    • com.ibm.commerce.promotion.uniquecode.generator.SequencePattern
  • All Implemented Interfaces:
    Pattern


    public class SequencePattern
    extends java.lang.Object
    implements Pattern
    The class generates codes for Sequence pattern. It implements Pattern interface.

    A general sequence pattern definition is "S+startingNumber/Increment". The mask character "S" means the pattern is a sequence pattern. The length of the mask character represents the length of the codes. The "startingNumber" defines the start number of the sequence. The "Increment" defines the increment between two codes.

    For example, [SSSS+100/20] represents a sequence starting at 0100 and incrementing by 20.

    For example, [SSSS+100] represents a sequence starting at 0100 and incrementing by 1.

    For example, [SSSS] represents a sequence starting at 0000 and incrementing by 1.

    See Also:
    Pattern
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String COPYRIGHT
      IBM Copyright notice field.
    • Constructor Summary

      Constructors 
      Constructor and Description
      SequencePattern()
      Constructor of the sequence pattern.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.String getCode()
      This method gets the generated sequence string
      char getMaskCharacter()
      This method gets the mask character "S"
      java.lang.String getPatternDefinition()
      This method gets the pattern definition string
      java.math.BigDecimal getPatternSpace()
      This method gets the size of the pattern space
      void setPatternDefinition(java.lang.String patternDefIn)
      This method sets the pattern definition string
      boolean validatePattern()
      Check whether the pattern definition is correct
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM Copyright notice field.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SequencePattern

        public SequencePattern()
        Constructor of the sequence pattern.

        It sets the initial value of the start number, increments and current code.

    • Method Detail

      • getCode

        public java.lang.String getCode()
        This method gets the generated sequence string
        Specified by:
        getCode in interface Pattern
        Returns:
        The sequence string
        See Also:
        Pattern.getCode()
      • getPatternSpace

        public java.math.BigDecimal getPatternSpace()
        This method gets the size of the pattern space

        It uses "Floor((Power(10, length of 'S') -1 - 'startingNumber')/'Increment')+1" to get the total size of possible codes numbers.

        Specified by:
        getPatternSpace in interface Pattern
        Returns:
        The total number of possible codes
        See Also:
        Pattern.getPatternSpace()
      • validatePattern

        public boolean validatePattern()
        Check whether the pattern definition is correct

        If the pattern has "/", then will check the "Increment" part is a positive integer.

        If the pattern has "+", then will check the "startingNumber" is a non-negative integer.

        At last, will check the mask string only contains "S".

        This method will return false if above conditions are not satisfied.

        Specified by:
        validatePattern in interface Pattern
        Returns:
        Validated result
        See Also:
        Pattern.validatePattern()