Generating UUID using fasterxml UUID generator

Views: 87   

fasterxml library has time/location based UUID generation methods. Following program shows how to generate UUID/ UUID strings using fasterxml's UUID generator.

import java.util.UUID;

import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.TimeBasedGenerator;

public class UUIDUtils {

    private static final TimeBasedGenerator generator = Generators.timeBasedGenerator();
    public static String getUUIDString() {
        return getUUID().toString();
    }

    public static UUID getUUID() {
        return generator.generate();
    }
}

Following is the sample usage of the above utility.

public class Main {
    public static void main(String[] args) {
        System.out.println(UUIDUtils.getUUIDString());
    }
}
On By