@@ -57,7 +57,7 @@ Add the following tag to `dependencies` tag in your `pom.xml` file. Change the v
5757<dependency >
5858 <groupId >io.azam.ulidj</groupId >
5959 <artifactId >ulidj</artifactId >
60- <version >1.1 .0</version >
60+ <version >2.0 .0</version >
6161</dependency >
6262```
6363
@@ -71,14 +71,18 @@ ULID ulid1 = ULID.randomULID();
7171// Using provided Random instance
7272ULID ulid2 = ULID . randomULID(ThreadLocalRandom . current());
7373// Using provided SecureRandom instance
74- ULID ulid3 = ULID . parseULID(" 003JZ9J6G80123456789abcdef" );
74+ ULID ulid3 = ULID . randomULID(SecureRandom . newInstance(" SHA1PRNG" ));
75+ // Using provided Clock instance
76+ ULID ulid4 = ULID . randomULID(Clock . systemUTC());
77+ // Using provided Clock and Random instance
78+ ULID ulid5 = ULID . randomULID(Clock . systemUTC(), SecureRandom . newInstance(" SHA1PRNG" ));
7579// Convert ULID string to ULID instance
76- ULID ulid4 = ULID . parseULID(" 003JZ9J6G80123456789abcdef" );
80+ ULID ulid6 = ULID . parseULID(" 003JZ9J6G80123456789abcdef" );
7781// Convert ULID binary to ULID instance
78- ULID ulid5 = ULID . parseULID(
82+ ULID ulid7 = ULID . parseULID(
7983 new byte [] {0x0 , 0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 , 0x8 , 0x9 , 0xa , 0xb , 0xc , 0xd , 0xe , 0xf });
8084// Instantiate a ULID instance from current time and provided entropy bytes
81- ULID ulid6 = ULID . generateULID(System . currentTimeMillis(), entropy);
85+ ULID ulid8 = ULID . generateULID(System . currentTimeMillis(), entropy);
8286// Sort ULID instances lexicographically
8387List<ULID > ulids = Arrays . asList(ulid1, ulid2, ulid3, ulid4, ulid5, ulid6);
8488Collections . sort(ulids);
@@ -93,11 +97,15 @@ String ulid1 = ULID.random();
9397String ulid2 = ULID . random(ThreadLocalRandom . current());
9498// Using provided SecureRandom instance
9599String ulid3 = ULID . random(SecureRandom . newInstance(" SHA1PRNG" ));
100+ // Using provided Clock instance
101+ String ulid4 = ULID . random(Clock . systemUTC());
102+ // Using provided Clock and Random instance
103+ String ulid5 = ULID . random(Clock . systemUTC(), SecureRandom . newInstance(" SHA1PRNG" ));
96104// Generate ULID string from current time and provided entropy bytes
97105byte [] entropy = new byte [] {0x0 , 0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 , 0x8 , 0x9 };
98- String ulid4 = ULID . generate(System . currentTimeMillis(), entropy);
106+ String ulid6 = ULID . generate(System . currentTimeMillis(), entropy);
99107// Convert ULID binary to ULID string
100- String ulid5 = ULID . fromBinary(
108+ String ulid7 = ULID . fromBinary(
101109 new byte [] {0x0 , 0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 , 0x8 , 0x9 , 0xa , 0xb , 0xc , 0xd , 0xe , 0xf });
102110```
103111
@@ -110,11 +118,15 @@ byte[] ulid1 = ULID.randomBinary();
110118byte [] ulid2 = ULID . randomBinary(ThreadLocalRandom . current());
111119// Using provided SecureRandom instance
112120byte [] ulid3 = ULID . randomBinary(SecureRandom . newInstance(" SHA1PRNG" ));
121+ // Using provided Clock instance
122+ byte [] ulid4 = ULID . randomBinary(Clock . systemUTC());
123+ // Using provided Clock and Random instance
124+ byte [] ulid5 = ULID . randomBinary(Clock . systemUTC(), SecureRandom . newInstance(" SHA1PRNG" ));
113125// Generate ULID string from current time and provided entropy bytes
114126byte [] entropy = new byte [] {0x0 , 0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 , 0x8 , 0x9 };
115- byte [] ulid4 = ULID . generateBinary(System . currentTimeMillis(), entropy);
127+ byte [] ulid6 = ULID . generateBinary(System . currentTimeMillis(), entropy);
116128// Convert ULID string to ULID binary
117- byte [] ulid5 = ULID . toBinary(" 003JZ9J6G80123456789abcdef" );
129+ byte [] ulid7 = ULID . toBinary(" 003JZ9J6G80123456789abcdef" );
118130```
119131
120132ULID utilities examples:
@@ -166,6 +178,23 @@ String ulid9 = monotonicUlid2.generate();
166178String ulid10 = monotonicUlid2. generate();
167179byte [] ulid11 = monotonicUlid2. generateBinary();
168180ULID ulid12 = monotonicUlid2. generateULID();
181+
182+ // Create a new independent instance of MonotonicULID using provided Clock instance
183+ MonotonicULID monotonicUlid3 = new MonotonicULID (Clock . systemUTC());
184+ String ulid13 = monotonicUlid3. generate();
185+ // Subsequent calls generates monotonic ULID
186+ String ulid14 = monotonicUlid3. generate();
187+ byte [] ulid15 = monotonicUlid3. generateBinary();
188+ ULID ulid16 = monotonicUlid3. generateULID();
189+
190+ // Create a new independent instance of MonotonicULID using provided Clock and Random instance
191+ MonotonicULID monotonicUlid4 =
192+ new MonotonicULID (Clock . systemUTC(), SecureRandom . newInstance(" SHA1PRNG" ));
193+ String ulid17 = monotonicUlid4. generate();
194+ // Subsequent calls generates monotonic ULID
195+ String ulid18 = monotonicUlid4. generate();
196+ byte [] ulid19 = monotonicUlid4. generateBinary();
197+ ULID ulid20 = monotonicUlid4. generateULID();
169198```
170199
171200## Develop
0 commit comments