Skip to content

Commit d6019dc

Browse files
change uuid to use long support in refinements
1 parent bd5c86c commit d6019dc

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

examples/demo/src/main/java/com/uuid/Test.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@
55
public class Test {
66

77
void test1(){
8-
UUID t = new UUID(10000L, 0L);
8+
long mostSigBits = 0x0000000000001000;
9+
UUID t = new UUID(mostSigBits, 0L);
910
t.clockSequence(); // possible
1011
}
1112

1213
void test2(){
13-
UUID t = UUID.randomUUID();
14-
t.clockSequence();
14+
long mostSigBits = 0x0670034000001222L;
15+
UUID t = new UUID(mostSigBits, 0L);
16+
t.clockSequence(); // possible
1517
}
1618

1719
void test3(){
20+
UUID t = UUID.randomUUID();
21+
t.clockSequence(); //error
22+
}
23+
24+
void test4(){
1825
UUID t = UUID.fromString("smt");
1926
t.clockSequence(); //possible
2027
t.node();
2128
t.variant();
2229
}
2330

24-
void test4(){
31+
void test5(){
2532
byte[] bytes = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2633
UUID t = UUID.nameUUIDFromBytes(bytes);
2734
t.variant();
@@ -31,4 +38,11 @@ void test4(){
3138
}
3239

3340

41+
void test6(){
42+
long mostSigBits = 0x0000000000002000;
43+
UUID t = new UUID(mostSigBits, 0L);
44+
t.clockSequence(); // error
45+
}
46+
47+
3448
}

examples/demo/src/main/java/com/uuid/UUIDRefinements.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
// (v/4096) % 16;
1212

1313
@ExternalRefinementsFor("java.util.UUID")
14-
@StateSet({"other", "maybeTime"})
14+
@StateSet({"other", "maybeTime", "timeBased"})
1515
@RefinementAlias("Version(int v) {v >= 0 && v <= 4}")
1616
@RefinementAlias("Variant(int v) {v == 0 || v == 2 || v == 6 || v == 7}")
1717
public interface UUIDRefinements {
1818

1919
// creation
20-
// would be cool to add
21-
// @StateRefinement(to="((mostSigBits/4096) % 16 == 1) ? timeBased(this) : other(this)")
22-
@StateRefinement(to="maybeTime(this)")
20+
@StateRefinement(to="((mostSigBits/4096) % 16 == 1) ? timeBased(this) : other(this)")
2321
void UUID(long mostSigBits, long leastSigBits);
2422

2523
//static
@@ -36,12 +34,15 @@ public interface UUIDRefinements {
3634

3735

3836
@StateRefinement(from="maybeTime(this)")
37+
@StateRefinement(from="timeBased(this)")
3938
int clockSequence();
4039

4140
@StateRefinement(from="maybeTime(this)")
41+
@StateRefinement(from="timeBased(this)")
4242
long timestamp();
4343

4444
@StateRefinement(from="maybeTime(this)")
45+
@StateRefinement(from="timeBased(this)")
4546
long node();
4647

4748
@Refinement("Variant(_)")

0 commit comments

Comments
 (0)