Skip to content

Commit 90201b6

Browse files
committed
fix: javadoc
1 parent a27c67a commit 90201b6

File tree

11 files changed

+349
-19
lines changed

11 files changed

+349
-19
lines changed

src/main/java/io/github/honhimw/uuid/Bytes.java

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**
66
* Byte array operation helper.
7-
* Without bounds check.
7+
* Without bounds check(for higher performance).
88
*
99
* @author honhimW
1010
* @see java.nio.ByteBuffer something like that, but without checking.
@@ -26,55 +26,123 @@ public Bytes(byte[] bytes) {
2626
this.pos = 0;
2727
}
2828

29+
/**
30+
* Append int to current position.
31+
*
32+
* @param value int value
33+
* @return self
34+
*/
2935
public Bytes putInt(int value) {
3036
this.pos = putInt(this.bytes, this.pos, value);
3137
return this;
3238
}
3339

40+
/**
41+
* Append long to current position.
42+
*
43+
* @param value long value
44+
* @return self
45+
*/
3446
public Bytes putLong(long value) {
3547
this.pos = putLong(this.bytes, this.pos, value);
3648
return this;
3749
}
3850

51+
/**
52+
* Append short to current position.
53+
*
54+
* @param value short value
55+
* @return self
56+
*/
3957
public Bytes putShort(short value) {
4058
this.pos = putShort(this.bytes, this.pos, value);
4159
return this;
4260
}
4361

62+
/**
63+
* Append byte to current position.
64+
*
65+
* @param value byte value
66+
* @return self
67+
*/
4468
public Bytes put(byte value) {
4569
this.pos = put(this.bytes, this.pos, value);
4670
return this;
4771
}
4872

73+
/**
74+
* Append byte to target position.
75+
*
76+
* @param value int value
77+
* @return self
78+
*/
4979
public Bytes put(int i, byte value) {
5080
this.bytes[i] = value;
5181
return this;
5282
}
5383

84+
/**
85+
* Append byte-array to current position.
86+
*
87+
* @param value byte array
88+
* @return self
89+
*/
5490
public Bytes put(byte[] value) {
5591
this.pos = put(this.bytes, this.pos, value);
5692
return this;
5793
}
5894

95+
/**
96+
* Append byte-array to current position.
97+
*
98+
* @param value byte array
99+
* @param offset value offset
100+
* @param length value length after offset
101+
* @return self
102+
*/
59103
public Bytes put(byte[] value, int offset, int length) {
60104
this.pos = put(this.bytes, this.pos, value, offset, length);
61105
return this;
62106
}
63107

108+
/**
109+
* Get result
110+
*
111+
* @return result
112+
*/
64113
public byte[] unwrap() {
65114
return this.bytes;
66115
}
67116

117+
/**
118+
* Get one byte by index
119+
*
120+
* @param i index
121+
* @return single byte
122+
*/
68123
public byte get(int i) {
69124
return this.bytes[i];
70125
}
71126

127+
/**
128+
* Copy byte-array from offset with length
129+
*
130+
* @param offset start position
131+
* @param length read length
132+
* @return result
133+
*/
72134
public byte[] get(int offset, int length) {
73135
byte[] _bytes = new byte[length];
74136
System.arraycopy(this.bytes, offset, _bytes, 0, length);
75137
return _bytes;
76138
}
77139

140+
/**
141+
* Read one int value from target index.
142+
*
143+
* @param i index
144+
* @return int value
145+
*/
78146
public int getInt(int i) {
79147
int v = 0;
80148
v |= Byte.toUnsignedInt(bytes[i]) << 24;
@@ -84,6 +152,12 @@ public int getInt(int i) {
84152
return v;
85153
}
86154

155+
/**
156+
* Read one long value from target index.
157+
*
158+
* @param i index
159+
* @return long value
160+
*/
87161
public long getLong(int i) {
88162
long v = 0;
89163
v |= Byte.toUnsignedLong(bytes[i]) << 56;
@@ -97,17 +171,34 @@ public long getLong(int i) {
97171
return v;
98172
}
99173

174+
/**
175+
* Read short int value from target index.
176+
*
177+
* @param i index
178+
* @return short value
179+
*/
100180
public short getShort(int i) {
101181
int v = 0;
102182
v |= Byte.toUnsignedInt(bytes[i]) << 8;
103183
v |= Byte.toUnsignedInt(bytes[i + 1]);
104184
return (short) v;
105185
}
106186

187+
/**
188+
* Get current position
189+
*
190+
* @return position
191+
*/
107192
public int position() {
108193
return this.pos;
109194
}
110195

196+
/**
197+
* Set current index.
198+
*
199+
* @param index target index
200+
* @return self
201+
*/
111202
public Bytes position(int index) {
112203
this.pos = index;
113204
return this;
@@ -142,6 +233,14 @@ public String toString() {
142233
return sb.toString();
143234
}
144235

236+
/**
237+
* Add int value into byte-array with index.
238+
*
239+
* @param dist target
240+
* @param index position
241+
* @param value value
242+
* @return next index
243+
*/
145244
public static int putInt(byte[] dist, int index, int value) {
146245
dist[index] = (byte) (value >> 24);
147246
dist[index + 1] = (byte) (value >> 16);
@@ -150,12 +249,28 @@ public static int putInt(byte[] dist, int index, int value) {
150249
return index + 4;
151250
}
152251

252+
/**
253+
* Add short value into byte-array with index.
254+
*
255+
* @param dist target
256+
* @param index position
257+
* @param value value
258+
* @return next index
259+
*/
153260
public static int putShort(byte[] dist, int index, short value) {
154261
dist[index] = (byte) (value >> 8);
155262
dist[index + 1] = (byte) value;
156263
return index + 2;
157264
}
158265

266+
/**
267+
* Add long value into byte-array with index.
268+
*
269+
* @param dist target
270+
* @param index position
271+
* @param value value
272+
* @return next index
273+
*/
159274
public static int putLong(byte[] dist, int index, long value) {
160275
dist[index] = (byte) (value >> 56);
161276
dist[index + 1] = (byte) (value >> 48);
@@ -168,11 +283,27 @@ public static int putLong(byte[] dist, int index, long value) {
168283
return index + 8;
169284
}
170285

286+
/**
287+
* Add byte value into byte-array with index.
288+
*
289+
* @param dist target
290+
* @param index position
291+
* @param value value
292+
* @return next index
293+
*/
171294
public static int put(byte[] dist, int index, byte value) {
172295
dist[index] = value;
173296
return index + 1;
174297
}
175298

299+
/**
300+
* Add byte-array into byte-array with index.
301+
*
302+
* @param dist target
303+
* @param index position
304+
* @param value value
305+
* @return next index
306+
*/
176307
public static int put(byte[] dist, int index, byte[] value) {
177308
for (byte b : value) {
178309
dist[index] = b;
@@ -181,6 +312,16 @@ public static int put(byte[] dist, int index, byte[] value) {
181312
return index;
182313
}
183314

315+
/**
316+
* Add int value into byte-array with index.
317+
*
318+
* @param dist target
319+
* @param index position
320+
* @param value source
321+
* @param offset source offset
322+
* @param length source length
323+
* @return next index
324+
*/
184325
public static int put(byte[] dist, int index, byte[] value, int offset, int length) {
185326
for (int i = 0; i < length; i++) {
186327
dist[index] = value[i + offset];
@@ -189,6 +330,13 @@ public static int put(byte[] dist, int index, byte[] value, int offset, int leng
189330
return index;
190331
}
191332

333+
/**
334+
* Copy byte-array from 0 into new array.
335+
*
336+
* @param src source
337+
* @param length read length
338+
* @return new array
339+
*/
192340
public static byte[] copyOf(byte[] src, int length) {
193341
byte[] dst = new byte[length];
194342
System.arraycopy(src, 0, dst, 0, length);

src/main/java/io/github/honhimw/uuid/ClockSequence.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,29 @@
1111

1212
public interface ClockSequence {
1313

14+
/**
15+
* Generate sequence by unix-timestamp
16+
*
17+
* @param seconds unix second
18+
* @param nanos unix nanosecond
19+
* @return clock sequence
20+
*/
1421
long generateSequence(long seconds, int nanos);
1522

23+
/**
24+
* Clock sequence bit-length in uuid.
25+
*
26+
* @return bit length
27+
*/
1628
int usableBits();
1729

30+
/**
31+
* Get current timestamp.
32+
* <p>
33+
* In most cases, millisecond is enough. {@link System#currentTimeMillis()} is much more faster than {@link Instant#now()}
34+
*
35+
* @return unix timestamp
36+
*/
1837
default Instant now() {
1938
return Instant.now();
2039
}

src/main/java/io/github/honhimw/uuid/Context.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,58 @@ public static Builder builder() {
3838
return new Builder();
3939
}
4040

41+
/**
42+
* Build a new UUIDv1 generator with current context.
43+
*
44+
* @return UUIDv1 generator
45+
*/
4146
public V1 v1() {
4247
return new V1(this);
4348
}
4449

50+
/**
51+
* Build a new UUIDv3 generator with current context.
52+
*
53+
* @param namespace UUIDv3 namespace
54+
* @return UUIDv3 generator
55+
*/
4556
public V3 v3(UUID namespace) {
4657
return new V3(this, namespace);
4758
}
4859

60+
/**
61+
* Build a new UUIDv4 generator with current context.
62+
*
63+
* @return UUIDv4 generator
64+
*/
4965
public V4 v4() {
5066
return new V4(this);
5167
}
5268

69+
/**
70+
* Build a new UUIDv5 generator with current context.
71+
*
72+
* @param namespace UUIDv5 namespace
73+
* @return UUIDv5 generator
74+
*/
5375
public V5 v5(UUID namespace) {
5476
return new V5(this, namespace);
5577
}
5678

79+
/**
80+
* Build a new UUIDv6 generator with current context.
81+
*
82+
* @return UUIDv6 generator
83+
*/
5784
public V6 v6() {
5885
return new V6(this);
5986
}
6087

88+
/**
89+
* Build a new UUIDv7 generator with current context.
90+
*
91+
* @return UUIDv7 generator
92+
*/
6193
public V7 v7() {
6294
return new V7(this);
6395
}

src/main/java/io/github/honhimw/uuid/Generator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
public interface Generator {
1313

14+
/**
15+
* No-args UUID generation.
16+
* <p>
17+
* For time-based generator, using current timestamp.
18+
* <p>
19+
* For name-based generator, using random bytes.
20+
* @return random uuid
21+
*/
1422
UUID next();
1523

1624
}

0 commit comments

Comments
 (0)