@@ -51,6 +51,7 @@ object NanoId {
5151 * @throws IllegalArgumentException if the alphabet is empty or larger than 255 characters, or if the size is not greater than zero.
5252 */
5353 @JvmOverloads
54+ @JvmStatic
5455 fun generate (
5556 @NotNull
5657 size : Int = 21,
@@ -84,6 +85,7 @@ object NanoId {
8485 * @return The generated optimized string.
8586 */
8687 @JvmOverloads
88+ @JvmStatic
8789 fun generateOptimized (@NotNull size : Int , @NotNull alphabet : String , @NotNull mask : Int , @NotNull step : Int , @NotNull random : Random = SecureRandom ()): String {
8890 val idBuilder = StringBuilder (size)
8991 val bytes = ByteArray (step)
@@ -107,6 +109,7 @@ object NanoId {
107109 * @param alphabet The set of characters to use for generating the string.
108110 * @return The additional bytes factor, rounded to two decimal places.
109111 */
112+ @JvmStatic
110113 fun calculateAdditionalBytesFactor (@NotNull alphabet : String ): Double {
111114 val mask = calculateMask(alphabet)
112115 return (1 + abs((mask - alphabet.length.toDouble()) / alphabet.length)).round(2 )
@@ -118,6 +121,7 @@ object NanoId {
118121 * @param alphabet The set of characters to use for generating the string.
119122 * @return The calculated mask value.
120123 */
124+ @JvmStatic
121125 fun calculateMask (@NotNull alphabet : String ) = (2 shl (Integer .SIZE - 1 - Integer .numberOfLeadingZeros(alphabet.length - 1 ))) - 1
122126
123127 /* *
@@ -128,6 +132,7 @@ object NanoId {
128132 * @param additionalBytesFactor The additional bytes factor. Default value is calculated using `calculateAdditionalBytesFactor()`.
129133 * @return The number of random bytes to generate in each iteration.
130134 */
135+ @JvmStatic
131136 @JvmOverloads
132137 fun calculateStep (@NotNull size : Int , @NotNull alphabet : String , @NotNull additionalBytesFactor : Double = calculateAdditionalBytesFactor(alphabet)) =
133138 ceil(additionalBytesFactor * calculateMask(alphabet) * size / alphabet.length).toInt()
0 commit comments