Skip to content

Collision-resistant ids optimized for horizontal scaling and performance

License

Notifications You must be signed in to change notification settings

thibaultmeyer/cuid-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CUID for Java

GitHub license Repository release Maven Repository size

Javadoc

Java implementation of CUID. Read more at CUID official website.


Build

To compile CUID for Java, you must ensure that Java 11 (or above) and Maven are correctly installed.

#> mvn package
#> mvn install

To speed up process, you can ignore unit tests by using: -DskipTests=true -Dmaven.test.skip=true.

How to use

<dependency>
  <groupId>io.github.thibaultmeyer</groupId>
  <artifactId>cuid</artifactId>
  <version>x.y.z</version>
</dependency>
final CUID cuid = CUID.randomCUID1();
System.out.println("CUID: " + cuid);
final CUID cuid = CUID.randomCUID2();
System.out.println("CUID (Version 2): " + cuid);
final int customLength = 8;  // Length must be, at least, 1
final CUID cuid = CUID.randomCUID2(customLength);
System.out.println("CUID (Version 2): " + cuid);
final CUID cuid = CUID.fromString("cl9gts1kw00393647w1z4v2tc");
System.out.println("CUID: " + cuid);
final boolean isValid = CUID.isValid("cl9gts1kw00393647w1z4v2tc");
System.out.println("Is 'cl9gts1kw00393647w1z4v2tc' a valid CUID ? " + isValid);

License

This project is released under terms of the MIT license.