Class AutoGeneratedIdUtil
java.lang.Object
com.ssgllc.fish.service.util.registered.AutoGeneratedIdUtil
-
Constructor Summary
ConstructorsConstructorDescriptionAutoGeneratedIdUtil
(com.ssgllc.fish.service.CustomIdentifierService customIdentifierService) -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 theCustomIdentifierService
, ensuring that each sequence is unique per key.static String
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
Pads the given string on the left to reach a specified size using the provided padding string.
This is a convenience method that delegates toleftPad(String, int, String)
.static boolean
resetOrInitSeqNo
(String key) Resets the sequence number to 0 or initializes it if it does not exist for the specified key.
This method interacts with theCustomIdentifierService
to ensure that sequences can be reinitialized or created anew, which is useful in scenarios requiring sequence renumbering or setup.static String
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.
-
Constructor Details
-
AutoGeneratedIdUtil
public AutoGeneratedIdUtil(com.ssgllc.fish.service.CustomIdentifierService customIdentifierService)
-
-
Method Details
-
getSeq
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
Retrieves the next sequence number as a string, starting from a specified initial value if necessary.
This method accesses a persistent sequence controlled by theCustomIdentifierService
, ensuring that each sequence is unique per key. If no sequence exists for the provided key, it starts withseqStart
.- 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
- IfseqStart
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
Resets the sequence number to 0 or initializes it if it does not exist for the specified key.
This method interacts with theCustomIdentifierService
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
Pads the given string on the left to reach a specified size using the provided padding string.
This is a convenience method that delegates toleftPad(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
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
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"
-