Class AutoGeneratedIdUtil

java.lang.Object
com.ssgllc.fish.service.util.registered.AutoGeneratedIdUtil

@Component public class AutoGeneratedIdUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    AutoGeneratedIdUtil(com.ssgllc.fish.service.CustomIdentifierService customIdentifierService)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Retrieves the next sequence number as a string for the specified key, starting from 1 if necessary.
    This method simplifies accessing sequences by defaulting to a starting value of 1 if no current sequence exists for the key.
    static String
    getSeqWithSeqStart(String key, Long seqStart)
    Retrieves the next sequence number as a string, starting from a specified initial value if necessary.
    This method accesses a persistent sequence controlled by the CustomIdentifierService, ensuring that each sequence is unique per key.
    static String
    leftPad(String str, int size, String padStr)
    Pads the given string on the left to reach a specified size using the provided padding string.
    This method ensures that the length of the result meets the specified size by adding the pad string to the beginning of the input string.
    static String
    pad(String str, int size, String padStr)
    Pads the given string on the left to reach a specified size using the provided padding string.
    This is a convenience method that delegates to leftPad(String, int, String).
    static boolean
    Resets the sequence number to 0 or initializes it if it does not exist for the specified key.
    This method interacts with the CustomIdentifierService to ensure that sequences can be reinitialized or created anew, which is useful in scenarios requiring sequence renumbering or setup.
    static String
    rightPad(String str, int size, String padStr)
    Pads the given string on the right to reach a specified size using the provided padding string.
    This method extends the length of the string by adding the pad string to the end until it reaches the specified size.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AutoGeneratedIdUtil

      public AutoGeneratedIdUtil(com.ssgllc.fish.service.CustomIdentifierService customIdentifierService)
  • Method Details

    • getSeq

      public static String getSeq(String key) throws Exception
      Retrieves the next sequence number as a string for the specified key, starting from 1 if necessary.
      This method simplifies accessing sequences by defaulting to a starting value of 1 if no current sequence exists for the key.
      Parameters:
      key - The key associated with the sequence.
      Returns:
      The next sequence number as a string.
      Throws:
      Exception - If there is an error in generating the sequence number.

      Groovy example:
      return autoGeneratedIdUtil.getSeq("myKey")

      Returns:
      "1"

      SpEL example:
      #getSeq("myKey")

      Returns:
      "1"
      Note: Throws an exception if there is an error in sequence generation.
    • getSeqWithSeqStart

      public static String getSeqWithSeqStart(String key, Long seqStart) throws Exception
      Retrieves the next sequence number as a string, starting from a specified initial value if necessary.
      This method accesses a persistent sequence controlled by the CustomIdentifierService, ensuring that each sequence is unique per key. If no sequence exists for the provided key, it starts with seqStart.
      Parameters:
      key - The key associated with the sequence.
      seqStart - The starting point for the sequence if one is not already established. Must be greater than 0.
      Returns:
      The next sequence number as a string.
      Throws:
      Exception - If seqStart is less than or equal to 0, or if there is an error in generating the sequence number.

      Groovy example:
      return autoGeneratedIdUtil.getSeqWithSeqStart("myKey", 100)

      Returns:
      "100"

      SpEL example:
      #getSeqWithSeqStart("myKey", 100)

      Returns:
      "100"
      Note: Throws an exception if seqStart is not valid or if there is an error in sequence generation.
    • resetOrInitSeqNo

      public static boolean resetOrInitSeqNo(String key) throws Exception
      Resets the sequence number to 0 or initializes it if it does not exist for the specified key.
      This method interacts with the CustomIdentifierService to ensure that sequences can be reinitialized or created anew, which is useful in scenarios requiring sequence renumbering or setup.
      Parameters:
      key - The key associated with the sequence.
      Returns:
      true if the sequence number was successfully reset or initialized; false if the key is empty or null.
      Throws:
      Exception - If there is an error in resetting or initializing the sequence number.

      Groovy example:
      return autoGeneratedIdUtil.resetOrInitSeqNo("myKey")

      Returns:
      true

      SpEL example:
      #resetOrInitSeqNo("myKey")

      Returns:
      true
      Note: Throws an exception if there is an issue with the operation.
    • pad

      public static String pad(String str, int size, String padStr)
      Pads the given string on the left to reach a specified size using the provided padding string.
      This is a convenience method that delegates to leftPad(String, int, String).
      Parameters:
      str - The string to be padded.
      size - The desired length of the new string.
      padStr - The string to pad with.
      Returns:
      The padded string, or the original string if it is already longer than the desired length.

      Groovy example:
      return stringUtil.pad("hello", 8, "0")

      Returns:
      "000hello"

      SpEL example:
      #pad("hello", 8, "0")

      Returns:
      "000hello"
    • leftPad

      public static String leftPad(String str, int size, String padStr)
      Pads the given string on the left to reach a specified size using the provided padding string.
      This method ensures that the length of the result meets the specified size by adding the pad string to the beginning of the input string.
      Parameters:
      str - The string to be padded.
      size - The desired length of the new string.
      padStr - The string to pad with.
      Returns:
      The padded string, or the original string if it is already longer than the desired length.

      Groovy example:
      return stringUtil.leftPad("hello", 8, "0")

      Returns:
      "000hello"

      SpEL example:
      #leftPad("hello", 8, "0")

      Returns:
      "000hello"
    • rightPad

      public static String rightPad(String str, int size, String padStr)
      Pads the given string on the right to reach a specified size using the provided padding string.
      This method extends the length of the string by adding the pad string to the end until it reaches the specified size.
      Parameters:
      str - The string to be padded.
      size - The desired length of the new string.
      padStr - The string to pad with.
      Returns:
      The padded string, or the original string if it is already longer than the desired length.

      Groovy example:
      return stringUtil.rightPad("hello", 8, "0")

      Returns:
      "hello000"

      SpEL example:
      #rightPad("hello", 8, "0")

      Returns:
      "hello000"