类 IdGenerator

java.lang.Object
com.abasecode.opencode.base.generator.IdGenerator

public class IdGenerator extends Object
作者:
Jon e-mail: ijonso123@gmail.com url: Jon's blog url: project github url: AbaseCode.com

Get 24-bit fixed-length sequential code. Used to generate sequential codes with dates. The first 8 bits are the year, month and date. The 9th bit is the microservice designator and takes values in the range 0-15 (displayed as hex 0-9A-F). The 10th bit is the machine designator and takes the value range 0-15 (displayed as 0-9A-F in hexadecimal). The last 14 bits are the sequence codes. Example: 20211202AB10098259438592

  • 字段详细资料

    • CODE_LENGTH

      private static final int CODE_LENGTH
      另请参阅:
    • APP_BIT

      private static final long APP_BIT
      另请参阅:
    • MACHINE_BIT

      private static final long MACHINE_BIT
      另请参阅:
    • SEQUENCE_BIT

      private static final long SEQUENCE_BIT
      另请参阅:
    • MAX_SEQUENCE

      private static final long MAX_SEQUENCE
      另请参阅:
    • MAX_MACHINE_NUM

      private static final long MAX_MACHINE_NUM
      另请参阅:
    • MAX_APP_NUM

      private static final long MAX_APP_NUM
      另请参阅:
    • MACHINE_LEFT

      private static final long MACHINE_LEFT
      另请参阅:
    • APP_LEFT

      private static final long APP_LEFT
      另请参阅:
    • TIME_LEFT

      private static final long TIME_LEFT
      另请参阅:
    • DATE_STRING

      private static final String DATE_STRING
    • DF

      private static final DateTimeFormatter DF
    • START_TIMESTAMP

      private static final long START_TIMESTAMP
    • appId

      private long appId
    • machineId

      private long machineId
    • sequence

      private long sequence
    • lastTimeStamp

      private long lastTimeStamp
    • appIdChar

      private String appIdChar
    • machineChar

      private String machineChar
  • 构造器详细资料

    • IdGenerator

      public IdGenerator(long appId, long machineId)
      The parameters are required
      参数:
      appId - Microservice Code,takes values in the range 0-15
      machineId - Machine code,takes values in the range 0-15
  • 方法详细资料

    • getNext

      private long getNext()
      Get millis
      返回:
      millis
    • getNew

      private long getNew()
      Get millis
      返回:
      millis
    • genId

      public String genId()
      Generate ID
      返回:
      24bit ID
    • cast

      private String cast(String StringNumber)
      Converts to a length-compliant string
      参数:
      StringNumber -
      返回:
      14bit string
    • getZero

      private String getZero(int x)
      Left-aligned zero complement
      参数:
      x - Number of replenishments required
      返回:
      14bit string