Skip to content

Commit 72eed51

Browse files
committed
Rewrite docs #73
1 parent 4ec2346 commit 72eed51

File tree

82 files changed

+1602
-5229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1602
-5229
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ hs_err_pid*
4646

4747
notes/*
4848

49+
docs/javadoc/*
50+
4951

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file.
66

77
Nothing unreleased.
88

9+
## [5.1.2] - 2022-09-11
10+
11+
Rewrite docs. #73
912

1013
## [5.1.1] - 2022-08-21
1114

@@ -343,7 +346,8 @@ Remove `Fingerprint` // too complex
343346
- Removed UuidSettings.getNodeIdentifierDeprecated // remove deprecated
344347
- Renamed UuidSettings to UuidCreatorSettings
345348

346-
[unreleased]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-5.1.1...HEAD
349+
[unreleased]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-5.1.2...HEAD
350+
[5.1.2]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-5.1.1...uuid-creator-5.1.2
347351
[5.1.1]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-5.1.0...uuid-creator-5.1.1
348352
[5.1.0]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-5.0.0...uuid-creator-5.1.0
349353
[5.0.0]: https://github.com/f4b6a3/uuid-creator/compare/uuid-creator-4.6.1...uuid-creator-5.0.0

README.md

+36-200
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11

2+
23
UUID Creator
34
======================================================
45

5-
This is a Java library for [RFC-4122 Universally Unique Identifiers](https://en.wikipedia.org/wiki/Universally_unique_identifier).
6+
This is a Java library for generating [Universally Unique Identifiers](https://en.wikipedia.org/wiki/Universally_unique_identifier).
7+
8+
UUIDs:
69

7-
RFC-4122 UUIDs:
10+
* __UUID Version 1__: the time-based version with gregorian epoch specified in RFC-4122;
11+
* __UUID Version 2__: the DCE Security version with embedded POSIX UIDs specified in DCE 1.1;
12+
* __UUID Version 3__: the name-based version that uses MD5 hashing specified in RFC-4122;
13+
* __UUID Version 4__: the randomly or pseudo-randomly generated version specified in RFC-4122;
14+
* __UUID Version 5__: the name-based version that uses SHA-1 hashing specified in RFC-4122;
15+
* __UUID Version 6__: the time-ordered version with gregorian epoch proposed as [new UUID format](https://github.com/uuid6/uuid6-ietf-draft);
16+
* __UUID Version 7__: the time-ordered version with Unix epoch proposed as [new UUID format](https://github.com/uuid6/uuid6-ietf-draft).
817

9-
* __Version 1__: Time-based;
10-
* __Version 2__: DCE Security;
11-
* __Version 3__: Name-based with MD5;
12-
* __Version 4__: Random-based;
13-
* __Version 5__: Name-based with SHA1;
14-
* __Version 6__: Time-ordered ([IETF draft](https://github.com/uuid6/uuid6-ietf-draft));
15-
* __Version 7__: Time-ordered with Unix Epoch ([IETF draft](https://github.com/uuid6/uuid6-ietf-draft)).
18+
COMB GUIDs:
1619

17-
Non-standard GUIDs:
20+
* __Prefix COMB GUID__: a combination of random bytes with a prefix (millisecond);
21+
* __Suffix COMB GUID__: a combination of random bytes with a suffix (millisecond);
22+
* __Short Prefix COMB GUID__: a combination of random bytes with a small prefix (minute);
23+
* __Short Suffix COMB GUID__: a combination of random bytes with a small suffix (minute).
1824

19-
* __Prefix COMB__: combination of the creation millisecond (prefix) with random bytes;
20-
* __Suffix COMB__: combination of the creation millisecond (suffix) with random bytes;
21-
* __Short Prefix COMB__: combination the creation minute (prefix) with random bytes;
22-
* __Short Suffix COMB__: combination the creation minute (suffix) with random bytes.
25+
This project contains a [micro benchmark](https://github.com/f4b6a3/uuid-creator/tree/master/benchmark) and a good amount of [unit tests](https://github.com/f4b6a3/uuid-creator/tree/master/src/test/java/com/github/f4b6a3/uuid).
2326

24-
This library contains a good amount of [unit tests](https://github.com/f4b6a3/uuid-creator/tree/master/src/test/java/com/github/f4b6a3/uuid). It also has a [micro benchmark](https://github.com/f4b6a3/uuid-creator/tree/master/benchmark) for you to check if the performance is good enough.
27+
The jar file can be downloaded directly from [maven.org](https://repo1.maven.org/maven2/com/github/f4b6a3/uuid-creator/).
2528

26-
Read the [Wiki pages](https://github.com/f4b6a3/uuid-creator/wiki).
29+
Read the [Wiki pages](https://github.com/f4b6a3/uuid-creator/wiki) and the [Javadocs](https://javadoc.io/doc/com.github.f4b6a3/uuid-creator).
2730

2831
Maven dependency
2932
------------------------------------------------------
@@ -35,7 +38,7 @@ Add these lines to your `pom.xml`:
3538
<dependency>
3639
<groupId>com.github.f4b6a3</groupId>
3740
<artifactId>uuid-creator</artifactId>
38-
<version>5.1.1</version>
41+
<version>5.1.2</version>
3942
</dependency>
4043
```
4144
See more options in [maven.org](https://search.maven.org/artifact/com.github.f4b6a3/uuid-creator).
@@ -50,242 +53,74 @@ Module and bundle names are the same as the root package name.
5053
How to Use
5154
------------------------------------------------------
5255

53-
### Library Facade
56+
All UUID types can be created from the facade [`UuidCreator`](https://github.com/f4b6a3/uuid-creator/blob/master/src/main/java/com/github/f4b6a3/uuid/UuidCreator.java).
5457

55-
Create a [Random-based](https://github.com/f4b6a3/uuid-creator/wiki/1.4.-Random-based) UUID:
58+
Create a [Random-based](https://github.com/f4b6a3/uuid-creator/wiki/1.4.-Random-based) unique identifier (UUIDv4):
5659

5760
```java
5861
UUID uuid = UuidCreator.getRandomBased();
5962
```
6063

61-
Create a [Time-based](https://github.com/f4b6a3/uuid-creator/wiki/1.1.-Time-based) UUID:
64+
Create a [Time-based](https://github.com/f4b6a3/uuid-creator/wiki/1.1.-Time-based) unique identifier (UUIDv1):
6265

6366
```java
6467
UUID uuid = UuidCreator.getTimeBased();
6568
```
6669

67-
Create a [Time-ordered](https://github.com/f4b6a3/uuid-creator/wiki/1.6.-Time-ordered) UUID:
70+
Create a [Time-ordered](https://github.com/f4b6a3/uuid-creator/wiki/1.6.-Time-ordered) unique identifier (UUIDv6):
6871

6972
```java
7073
UUID uuid = UuidCreator.getTimeOrdered();
7174
```
7275

73-
Create a [Time-ordered with Unix Epoch](https://github.com/f4b6a3/uuid-creator/wiki/1.7.-Time-ordered-epoch) UUID:
76+
Create a [Time-ordered with Unix Epoch](https://github.com/f4b6a3/uuid-creator/wiki/1.7.-Time-ordered-epoch) unique identifier (UUIDv7)
7477

7578
```java
7679
UUID uuid = UuidCreator.getTimeOrderedEpoch();
7780
```
7881

79-
Create a [Name-based with MD5](https://github.com/f4b6a3/uuid-creator/wiki/1.3.-Name-based-with-MD5) UUID:
82+
Create a [Name-based with MD5](https://github.com/f4b6a3/uuid-creator/wiki/1.3.-Name-based-with-MD5) unique identifier (UUIDv3)
8083

8184
```java
82-
String name = "https://github.com/";
83-
UUID uuid = UuidCreator.getNameBasedMd5(UuidNamespace.NAMESPACE_URL, name);
85+
UUID uuid = UuidCreator.getNameBasedMd5(UuidNamespace.NAMESPACE_URL, "https://github.com/");
8486
```
8587

86-
Create a [Name-based with SHA-1](https://github.com/f4b6a3/uuid-creator/wiki/1.5.-Name-based-with-SHA-1) UUID:
88+
Create a [Name-based with SHA-1](https://github.com/f4b6a3/uuid-creator/wiki/1.5.-Name-based-with-SHA-1) unique identifier (UUIDv5)
8789

8890
```java
89-
String name = "https://github.com/";
90-
UUID uuid = UuidCreator.getNameBasedSha1(UuidNamespace.NAMESPACE_URL, name);
91+
UUID uuid = UuidCreator.getNameBasedSha1(UuidNamespace.NAMESPACE_URL, "https://github.com/");
9192
```
9293

93-
Create a [DCE Security](https://github.com/f4b6a3/uuid-creator/wiki/1.2.-DCE-Security) UUID:
94+
Create a [DCE Security](https://github.com/f4b6a3/uuid-creator/wiki/1.2.-DCE-Security) unique identifier (UUIDv2)
9495

9596
```java
96-
int localIdentifier = 1701;
97-
UUID uuid = UuidCreator.getDceSecurity(UuidLocalDomain.LOCAL_DOMAIN_PERSON, localIdentifier);
97+
UUID uuid = UuidCreator.getDceSecurity(UuidLocalDomain.LOCAL_DOMAIN_PERSON, 1234);
9898
```
9999

100-
Create a [Prefix COMB](https://github.com/f4b6a3/uuid-creator/wiki/2.1.-Prefix-COMB) GUID:
100+
Create a [Prefix COMB GUID](https://github.com/f4b6a3/uuid-creator/wiki/2.1.-Prefix-COMB):
101101

102102
```java
103103
UUID uuid = UuidCreator.getPrefixComb();
104104
```
105105

106-
Create a [Suffix COMB](https://github.com/f4b6a3/uuid-creator/wiki/2.2.-Suffix-COMB) GUID:
106+
Create a [Suffix COMB GUID](https://github.com/f4b6a3/uuid-creator/wiki/2.2.-Suffix-COMB):
107107

108108
```java
109109
UUID uuid = UuidCreator.getSuffixComb();
110110
```
111111

112-
Create a [Short Prefix COMB](https://github.com/f4b6a3/uuid-creator/wiki/2.3.-Short-Prefix-COMB) GUID:
112+
Create a [Short Prefix COMB GUID](https://github.com/f4b6a3/uuid-creator/wiki/2.3.-Short-Prefix-COMB):
113113

114114
```java
115115
UUID uuid = UuidCreator.getShortPrefixComb();
116116
```
117117

118-
Create a [Short Suffix COMB](https://github.com/f4b6a3/uuid-creator/wiki/2.4.-Short-Suffix-COMB) GUID:
118+
Create a [Short Suffix COMB GUID](https://github.com/f4b6a3/uuid-creator/wiki/2.4.-Short-Suffix-COMB):
119119

120120
```java
121121
UUID uuid = UuidCreator.getShortSuffixComb();
122122
```
123123

124-
### Library Utilities
125-
126-
This library provides many utilities for validation, version checking, information extraction, etc.
127-
128-
Validate a UUID string:
129-
130-
```java
131-
UuidValidator.isValid(uuid);
132-
UuidValidator.validate(uuid); // Throws an exception if INVALID
133-
```
134-
135-
Check the version of UUID:
136-
137-
```java
138-
UuidUtil.isTimeBased(uuid);
139-
UuidUtil.isTimeOrdered(uuid);
140-
UuidUtil.isRandomBased(uuid);
141-
```
142-
Extract information from a UUID:
143-
144-
```java
145-
Instant instant = UuidUtil.getInstant(uuid);
146-
int clocksq = UuidUtil.getClockSequence(uuid);
147-
long nodeid = UuidUtil.getNodeIdentifier(uuid);
148-
UuidVersion version = UuidUtil.getVersion(uuid);
149-
UuidVariant variant = UuidUtil.getVariant(uuid);
150-
```
151-
152-
Extract information from a COMB GUID:
153-
154-
```java
155-
long prefix = UuidUtil.getPrefix(comb); // Unix milliseconds
156-
long suffix = UuidUtil.getSuffix(comb); // Unix milliseconds
157-
Instant instant = UuidUtil.getPrefixInstant(comb);
158-
Instant instant = UuidUtil.getSuffixInstant(comb);
159-
```
160-
161-
Get the machine ID:
162-
163-
```java
164-
long id = MachineId.getMachineId(); // 0x7bc3cfd7844f46ad (8918200211668420269)
165-
UUID uuid = MachineId.getMachineUuid(); // 7bc3cfd7-844f-46ad-81a9-1aa22d3c427a
166-
```
167-
168-
### Library Codecs
169-
170-
This library also provides many codecs for canonical string, byte array, base-n, slugs, etc.
171-
172-
#### Main codecs
173-
174-
Convert a UUID to and from [byte array](https://github.com/f4b6a3/uuid-creator/wiki/4.0.-Library-codecs#binarycodec):
175-
176-
```java
177-
UUID uuid = BinaryCodec.INSTANCE.decode(/* 16 bytes */);
178-
byte[] bytes = BinaryCodec.INSTANCE.encode(uuid);
179-
```
180-
Convert a UUID to and from [canonical string](https://github.com/f4b6a3/uuid-creator/wiki/4.0.-Library-codecs#stringcodec):
181-
182-
```java
183-
// 7x faster than `UUID.fromString()` and `UUID.toString()`
184-
UUID uuid = StringCodec.INSTANCE.decode("01234567-89ab-4def-a123-456789abcdef");
185-
String string = StringCodec.INSTANCE.encode(uuid);
186-
```
187-
188-
Convert a UUID to and from [URI](https://github.com/f4b6a3/uuid-creator/wiki/4.0.-Library-codecs#uricodec):
189-
190-
```java
191-
UUID uuid = UriCodec.INSTANCE.decode("urn:uuid:01234567-89ab-4def-a123-456789abcdef");
192-
URI uri = UriCodec.INSTANCE.encode(uuid);
193-
```
194-
195-
#### Base-N codecs
196-
197-
There are base-n codecs for base-16, base-32, base-58, base-62 and base-64.
198-
199-
Custom codecs can be instantiated with `BaseNCodec.newInstance(int|String)`.
200-
201-
Convert a UUID to and from [base-n](https://github.com/f4b6a3/uuid-creator/wiki/4.0.-Library-codecs#base-n-codecs):
202-
203-
```java
204-
// 22x faster than `UUID.toString().replaceAll("-", "")`
205-
UUID uuid = Base16Codec.INSTANCE.decode("0123456789ab4defa123456789abcdef");
206-
String string = Base16Codec.INSTANCE.encode(uuid);
207-
```
208-
209-
```java
210-
UUID uuid = Base32Codec.INSTANCE.decode("aerukz4jvng67ijdivtytk6n54");
211-
String string = Base32Codec.INSTANCE.encode(uuid);
212-
```
213-
214-
```java
215-
UUID uuid = Base58BtcCodec.INSTANCE.decode("199dn6s7UNiX3LyNkQ1Cfx");
216-
String string = Base58BtcCodec.INSTANCE.encode(uuid);
217-
```
218-
219-
```java
220-
UUID uuid = Base62Codec.INSTANCE.decode("0296tiiBY28FKCYq1PVSGd");
221-
String string = Base62Codec.INSTANCE.encode(uuid);
222-
```
223-
224-
```java
225-
UUID uuid = Base64UrlCodec.INSTANCE.decode("ASNFZ4mrTe-hI0VniavN7w");
226-
String string = Base64UrlCodec.INSTANCE.encode(uuid);
227-
```
228-
229-
Convert a UUID to and from a *custom* base-n:
230-
231-
```java
232-
// a base-20 string using a CUSTOM radix (20)
233-
int radix = 20; // expanded to "0123456789abcdefghij"
234-
BaseNCodec codec = BaseNCodec.newInstance(radix);
235-
236-
UUID uuid = codec.decode("00b5740h195313554732654bjhj9e7");
237-
String string = codec.encode(uuid);
238-
```
239-
240-
```java
241-
// a base-10 string using a CUSTOM alphabet ("0-9")
242-
String alphabet = "0-9"; // expanded to "0123456789"
243-
BaseNCodec codec = BaseNCodec.newInstance(alphabet);
244-
245-
UUID uuid = codec.decode("001512366075203566477668990085887675887");
246-
String string = codec.encode(uuid);
247-
```
248-
249-
Using a fast division library to boost encoding speed:
250-
251-
```java
252-
// a base-62 codec using a fast division library, i.e., `libdivide`
253-
CustomDivider divider = x -> {
254-
/* my division code here */
255-
return new long[] { quotient, remainder };
256-
};
257-
BaseNCodec codec = BaseNCodec.newInstance(62, divider);
258-
```
259-
260-
#### Other codecs
261-
262-
Convert a UUID to and from [Slug](https://github.com/f4b6a3/uuid-creator/wiki/4.0.-Library-codecs#slugcodec):
263-
264-
```java
265-
UUID uuid = SlugCodec.INSTANCE.decode("SgEjRWeJq97xI0VniavN7w");
266-
String string = SlugCodec.INSTANCE.encode(uuid);
267-
```
268-
269-
Convert a UUID to and from [NCName](https://github.com/f4b6a3/uuid-creator/wiki/4.0.-Library-codecs#ncnamecodec):
270-
271-
```java
272-
UUID uuid = NcnameCodec.INSTANCE.decode("EASNFZ4mr3vEjRWeJq83vK");
273-
String string = NcnameCodec.INSTANCE.encode(uuid);
274-
```
275-
276-
Convert a UUID to and from [.Net Guid](https://github.com/f4b6a3/uuid-creator/wiki/4.0.-Library-codecs#dotnetguid1codec-and-dotnetguid4codec):
277-
278-
```java
279-
// Convert time-based (version 1) to .Net Guid
280-
UUID guid = DotNetGuid1Codec.INSTANCE.encode(uuid);
281-
UUID uuid = DotNetGuid1Codec.INSTANCE.decode(guid);
282-
```
283-
```java
284-
// Convert random-based (version 4) to .Net Guid
285-
UUID guid = DotNetGuid4Codec.INSTANCE.encode(uuid);
286-
UUID uuid = DotNetGuid4Codec.INSTANCE.encode(guid);
287-
```
288-
289124
Other identifier generators
290125
------------------------------------------------------
291126

@@ -299,3 +134,4 @@ License
299134
------------------------------------------------------
300135

301136
This library is Open Source software released under the [MIT license](https://opensource.org/licenses/MIT).
137+

benchmark/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
To execute the benchmark, run the script `./benchmark/run.sh`.
2+
3+
See the [benchmark page in the Wiki](https://github.com/f4b6a3/uuid-creator/wiki/5.0.-Benchmark).
4+

benchmark/src/main/java/benchmark/Throughput.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
//import com.github.f4b6a3.uuid.codec.base.Base64UrlCodec;
2424

2525
@Fork(1)
26-
@Threads(1)
26+
@Threads(4)
2727
@State(Scope.Benchmark)
28+
@BenchmarkMode(Mode.Throughput)
2829
@Warmup(iterations = 5, time = 1)
2930
@Measurement(iterations = 5, time = 3)
30-
@BenchmarkMode(Mode.Throughput)
3131
@OutputTimeUnit(TimeUnit.MILLISECONDS)
3232
public class Throughput {
3333

0 commit comments

Comments
 (0)