public Execution(ExecutionType type, String application) { this(type, ID_GENERATOR.nextULID(), application); }
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 Value nextValue(long timestamp) { return internalNextValue(timestamp, random); }
static String internalUIDString(long timestamp, Random random) { checkTimestamp(timestamp); char[] buffer = new char[26]; internalWriteCrockford(buffer, timestamp, 10, 0); // could use nextBytes(byte[] bytes) instead internalWriteCrockford(buffer, random.nextLong(), 8, 10); internalWriteCrockford(buffer, random.nextLong(), 8, 18); return new String(buffer); }
/** * 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()); }
public String nextULID(long timestamp) { return internalUIDString(timestamp, random); }
public void appendULID(StringBuilder stringBuilder) { Objects.requireNonNull(stringBuilder, "stringBuilder must not be null!"); internalAppendULID(stringBuilder, System.currentTimeMillis(), 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()); }
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); } }
public static Value parseULID(String ulidString) { Objects.requireNonNull(ulidString, "ulidString must not be null!"); if(ulidString.length() != 26) { throw new IllegalArgumentException("ulidString must be exactly 26 chars long."); } String timeString = ulidString.substring(0, 10); long time = internalParseCrockford(timeString); if ((time & TIMESTAMP_OVERFLOW_MASK) != 0) { throw new IllegalArgumentException("ulidString must not exceed '7ZZZZZZZZZZZZZZZZZZZZZZZZZ'!"); } String part1String = ulidString.substring(10, 18); String part2String = ulidString.substring(18); long part1 = internalParseCrockford(part1String); long part2 = internalParseCrockford(part2String); long most = (time << 16) | (part1 >>> 24); long least = part2 | (part1 << 40); return new Value(most, least); }
static String internalUIDString(long timestamp, Random random) { checkTimestamp(timestamp); char[] buffer = new char[26]; internalWriteCrockford(buffer, timestamp, 10, 0); // could use nextBytes(byte[] bytes) instead internalWriteCrockford(buffer, random.nextLong(), 8, 10); internalWriteCrockford(buffer, random.nextLong(), 8, 18); return new String(buffer); }
/** * 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()); }
public String nextULID(long timestamp) { return internalUIDString(timestamp, random); }
public void appendULID(StringBuilder stringBuilder) { Objects.requireNonNull(stringBuilder, "stringBuilder must not be null!"); internalAppendULID(stringBuilder, System.currentTimeMillis(), 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()); }
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); } }
public static Value parseULID(String ulidString) { Objects.requireNonNull(ulidString, "ulidString must not be null!"); if(ulidString.length() != 26) { throw new IllegalArgumentException("ulidString must be exactly 26 chars long."); } String timeString = ulidString.substring(0, 10); long time = internalParseCrockford(timeString); if ((time & TIMESTAMP_OVERFLOW_MASK) != 0) { throw new IllegalArgumentException("ulidString must not exceed '7ZZZZZZZZZZZZZZZZZZZZZZZZZ'!"); } String part1String = ulidString.substring(10, 18); String part2String = ulidString.substring(18); long part1 = internalParseCrockford(part1String); long part2 = internalParseCrockford(part2String); long most = (time << 16) | (part1 >>> 24); long least = part2 | (part1 << 40); return new Value(most, least); }
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); }