All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.soffa.foundation.commons.IdGenerator Maven / Gradle / Ivy

The newest version!
package io.soffa.foundation.commons;

import com.aventrix.jnanoid.jnanoid.NanoIdUtils;

import java.nio.ByteBuffer;
import java.util.UUID;

@SuppressWarnings("PMD.ClassNamingConventions")
public final class IdGenerator {

    private IdGenerator() {
    }

    public static String shortUUID() {
        return shortUUID("");
    }

    public static String shortUUID(String... prefix) {
        UUID uuid = UUID.randomUUID();
        long l = ByteBuffer.wrap(uuid.toString().getBytes()).getLong();
        return StringUtil.prefix(Long.toString(l, Character.MAX_RADIX), prefix);
    }

    public static String secureRandomId() {
        return secureRandomId("");
    }

    public static String secureRandomId(String prefix) {
        return StringUtil.prefix(NanoIdUtils.randomNanoId(), prefix);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy