Skip to content

nanoflakes/nanoflakes-java

Repository files navigation

Nanoflakes - Java

Maven metadata URL GitHub issues License Twitter

Reference implementation of nanoflakes for Java.

Licensed under the MIT License.

Installation

Using in Gradle:

repositories {
  maven { url = 'https://maven.cafeteria.dev' }
}

dependencies {
  implementation 'com.github.nanoflakes:nanoflakes-java:VERSION'
}

Env variables required to build

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>

Usage

  • 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.
  • Use NanoflakeGenerator.next() to get a new nanoflake.
  • The Nanoflake class is the result type NanoflakeGenerator.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.

Support

Extra support is given on Aru's Discord Server.

Aru's Discord Server