Reference implementation of nanoflakes for Java.
Licensed under the MIT License.
Using in Gradle:
repositories {
maven { url = 'https://maven.cafeteria.dev' }
}
dependencies {
implementation 'com.github.nanoflakes:nanoflakes-java:VERSION'
}
mcdUsername and mcdPassword are needed for maven repository authentication. They are stored in gradle.properties
Using in Maven:
<repositories>
<repository>
<id>cafeteria</id>
<name>cafeteria</name>
<url>https://maven.cafeteria.dev</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.nanoflakes</groupId>
<artifactId>nanoflakes-java</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
- The
Ǹanoflakes
class contains utility methods for handling with nanoflakes. - Use
Nanoflakes.localGenerator(epoch, generatorId)
to create a local nanoflake generator.- You can get an epoch by calling
System.currentTimeMillis()
in a Java shell (jjs
,jshell
, etc). - A generator ID must be in the 0-1023 range.
- You can get an epoch by calling
- Use
NanoflakeGenerator.next()
to get a new nanoflake. - The
Nanoflake
class is the result typeNanoflakeGenerator.next()
. It can be used as-is, or getting it's raw or encoded value. It also features utility methods such as getting the creation time of the nanoflake.
Extra support is given on Aru's Discord Server.