public String nextULID(long timestamp) { return internalUIDString(timestamp, random); }
public Value nextValue(long timestamp) { return internalNextValue(timestamp, random); }
public Execution(ExecutionType type, String application) { this(type, ID_GENERATOR.nextULID(), application); }
/** * Returns the next monotonic value. If an overflow happened while incrementing * the random part of the given previous ULID value then the returned value will * have a zero random part. * * @param previousUlid the previous ULID value. * @param timestamp the timestamp of the next ULID value. * @return the next monotonic value. */ public Value nextMonotonicValue(Value previousUlid, long timestamp) { Objects.requireNonNull(previousUlid, "previousUlid must not be null!"); if(previousUlid.timestamp() == timestamp) { return previousUlid.increment(); } return nextValue(timestamp); }
static Value internalNextValue(long timestamp, Random random) { checkTimestamp(timestamp); // could use nextBytes(byte[] bytes) instead long mostSignificantBits = random.nextLong(); long leastSignificantBits = random.nextLong(); mostSignificantBits &= 0xFFFF; mostSignificantBits |= (timestamp << 16); return new Value(mostSignificantBits, leastSignificantBits); }
@Override public String toString() { char[] buffer = new char[26]; internalWriteCrockford(buffer, timestamp(), 10, 0); long value = ((mostSignificantBits & 0xFFFFL) << 24); long interim = (leastSignificantBits >>> 40); value = value | interim; internalWriteCrockford(buffer, value, 8, 10); internalWriteCrockford(buffer, leastSignificantBits, 8, 18); return new String(buffer); } }
/** * Returns the next monotonic value or empty if an overflow happened while incrementing * the random part of the given previous ULID value. * * @param previousUlid the previous ULID value. * @param timestamp the timestamp of the next ULID value. * @return the next monotonic value or empty if an overflow happened. */ public Optional<Value> nextStrictlyMonotonicValue(Value previousUlid, long timestamp) { Value result = nextMonotonicValue(previousUlid, timestamp); if(result.compareTo(previousUlid) < 1) { return Optional.empty(); } return Optional.of(result); }
static void internalAppendULID(StringBuilder builder, long timestamp, Random random) { checkTimestamp(timestamp); internalAppendCrockford(builder, timestamp, 10); // could use nextBytes(byte[] bytes) instead internalAppendCrockford(builder, random.nextLong(), 8); internalAppendCrockford(builder, random.nextLong(), 8); }
/** * Returns the next monotonic value or empty if an overflow happened while incrementing * the random part of the given previous ULID value. * * @param previousUlid the previous ULID value. * @return the next monotonic value or empty if an overflow happened. */ public Optional<Value> nextStrictlyMonotonicValue(Value previousUlid) { return nextStrictlyMonotonicValue(previousUlid, System.currentTimeMillis()); }
/** * Returns the next monotonic value. If an overflow happened while incrementing * the random part of the given previous ULID value then the returned value will * have a zero random part. * * @param previousUlid the previous ULID value. * @return the next monotonic value. */ public Value nextMonotonicValue(Value previousUlid) { return nextMonotonicValue(previousUlid, System.currentTimeMillis()); }
/** * Returns the next monotonic value. If an overflow happened while incrementing * the random part of the given previous ULID value then the returned value will * have a zero random part. * * @param previousUlid the previous ULID value. * @param timestamp the timestamp of the next ULID value. * @return the next monotonic value. */ public Value nextMonotonicValue(Value previousUlid, long timestamp) { Objects.requireNonNull(previousUlid, "previousUlid must not be null!"); if(previousUlid.timestamp() == timestamp) { return previousUlid.increment(); } return nextValue(timestamp); }
static Value internalNextValue(long timestamp, Random random) { checkTimestamp(timestamp); // could use nextBytes(byte[] bytes) instead long mostSignificantBits = random.nextLong(); long leastSignificantBits = random.nextLong(); mostSignificantBits &= 0xFFFF; mostSignificantBits |= (timestamp << 16); return new Value(mostSignificantBits, leastSignificantBits); }
@Override public String toString() { char[] buffer = new char[26]; internalWriteCrockford(buffer, timestamp(), 10, 0); long value = ((mostSignificantBits & 0xFFFFL) << 24); long interim = (leastSignificantBits >>> 40); value = value | interim; internalWriteCrockford(buffer, value, 8, 10); internalWriteCrockford(buffer, leastSignificantBits, 8, 18); return new String(buffer); } }
/** * Returns the next monotonic value or empty if an overflow happened while incrementing * the random part of the given previous ULID value. * * @param previousUlid the previous ULID value. * @param timestamp the timestamp of the next ULID value. * @return the next monotonic value or empty if an overflow happened. */ public Optional<Value> nextStrictlyMonotonicValue(Value previousUlid, long timestamp) { Value result = nextMonotonicValue(previousUlid, timestamp); if(result.compareTo(previousUlid) < 1) { return Optional.empty(); } return Optional.of(result); }
static void internalAppendULID(StringBuilder builder, long timestamp, Random random) { checkTimestamp(timestamp); internalAppendCrockford(builder, timestamp, 10); // could use nextBytes(byte[] bytes) instead internalAppendCrockford(builder, random.nextLong(), 8); internalAppendCrockford(builder, random.nextLong(), 8); }
public String nextULID() { return nextULID(System.currentTimeMillis()); }
public String nextULID(long timestamp) { return internalUIDString(timestamp, random); }
public Value nextValue(long timestamp) { return internalNextValue(timestamp, random); }
/** * Returns the next monotonic value or empty if an overflow happened while incrementing * the random part of the given previous ULID value. * * @param previousUlid the previous ULID value. * @return the next monotonic value or empty if an overflow happened. */ public Optional<Value> nextStrictlyMonotonicValue(Value previousUlid) { return nextStrictlyMonotonicValue(previousUlid, System.currentTimeMillis()); }
/** * Returns the next monotonic value. If an overflow happened while incrementing * the random part of the given previous ULID value then the returned value will * have a zero random part. * * @param previousUlid the previous ULID value. * @return the next monotonic value. */ public Value nextMonotonicValue(Value previousUlid) { return nextMonotonicValue(previousUlid, System.currentTimeMillis()); }