Skip to content

Commit 6138e4a

Browse files
uuid
1 parent e1643c4 commit 6138e4a

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.uuid;
2+
3+
import java.util.UUID;
4+
5+
public class Test {
6+
7+
void test1(){
8+
UUID t = new UUID(10000L, 0L);
9+
t.clockSequence(); // possible
10+
}
11+
12+
void test2(){
13+
UUID t = UUID.randomUUID();
14+
t.clockSequence();
15+
}
16+
17+
void test3(){
18+
UUID t = UUID.fromString("smt");
19+
t.clockSequence(); //possible
20+
t.node();
21+
t.variant();
22+
}
23+
24+
void test4(){
25+
byte[] bytes = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
26+
UUID t = UUID.nameUUIDFromBytes(bytes);
27+
t.variant();
28+
t.version();
29+
t.timestamp();//error
30+
31+
}
32+
33+
34+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.uuid;
2+
3+
import java.util.UUID;
4+
5+
import liquidjava.specification.ExternalRefinementsFor;
6+
import liquidjava.specification.Refinement;
7+
import liquidjava.specification.RefinementAlias;
8+
import liquidjava.specification.StateRefinement;
9+
import liquidjava.specification.StateSet;
10+
// 0x000000000000F000
11+
// (v/4096) % 16;
12+
13+
@ExternalRefinementsFor("java.util.UUID")
14+
@StateSet({"other", "maybeTime"})
15+
@RefinementAlias("Version(int v) {v >= 0 && v <= 4}")
16+
@RefinementAlias("Variant(int v) {v == 0 || v == 2 || v == 6 || v == 7}")
17+
public interface UUIDRefinements {
18+
19+
// creation
20+
// would be cool to add
21+
// @StateRefinement(to="((mostSigBits/4096) % 16 == 1) ? timeBased(this) : other(this)")
22+
@StateRefinement(to="maybeTime(this)")
23+
void UUID(long mostSigBits, long leastSigBits);
24+
25+
//static
26+
@Refinement("maybeTime(return)")
27+
UUID fromString(String name);
28+
29+
//static
30+
@Refinement("other(return)")
31+
UUID nameUUIDFromBytes(byte[] name);
32+
33+
//static
34+
@Refinement("other(return)")
35+
UUID randomUUID();
36+
37+
38+
@StateRefinement(from="maybeTime(this)")
39+
int clockSequence();
40+
41+
@StateRefinement(from="maybeTime(this)")
42+
long timestamp();
43+
44+
@StateRefinement(from="maybeTime(this)")
45+
long node();
46+
47+
@Refinement("Variant(_)")
48+
int variant();
49+
@Refinement("Version(_)")
50+
int version();
51+
52+
// int compareTo(UUID val);
53+
// boolean equals(Object obj);
54+
// long getLeastSignificantBits();
55+
// long getMostSignificantBits();
56+
// int hashCode();
57+
// String toString();
58+
59+
}

0 commit comments

Comments
 (0)