Skip to content

Commit 277bc9f

Browse files
added UUID case study
1 parent e35f5ce commit 277bc9f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.uuid;
2+
3+
import java.util.UUID;
4+
5+
import liquidjava.specification.ExternalRefinementsFor;
6+
import liquidjava.specification.Refinement;
7+
import liquidjava.specification.StateRefinement;
8+
import liquidjava.specification.StateSet;
9+
10+
@ExternalRefinementsFor("java.util.UUID")
11+
@StateSet({"time_based", "dce_security", "name_based", "random"})
12+
public interface UUIDRefinements {
13+
//@StateRefinement(from="leastSigBits & 0xC000000000000000 == 0xB000000000000000 && mostSigBits & 0x000000000000F000 == 0x0000000000001000", to="time_based(this)")
14+
public void UUID(long mostSigBits, long leastSigBits);
15+
16+
// QUESTION: is this how static methods should be specified?
17+
@Refinement("random(_)")
18+
public UUID randomUUID();
19+
20+
@Refinement("name_based(_)")
21+
public UUID nameUUIDFromBytes(byte[] name);
22+
23+
@Refinement("_ == 1 && time_based(this) || _ == 2 && dce_security(this) || _ == 3 && name_based(this) || _ == 4 && random(this)")
24+
public int version();
25+
26+
@StateRefinement(from="time_based(this)")
27+
public long timestamp();
28+
29+
@StateRefinement(from="time_based(this)")
30+
public int clockSequence();
31+
32+
@StateRefinement(from="time_based(this)")
33+
public long node();
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.uuid;
2+
3+
import java.util.UUID;
4+
5+
public class UUIDTest {
6+
void test1fail() {
7+
UUID u = UUID.randomUUID();
8+
u.timestamp(); // should report an error, because u is not time-based
9+
}
10+
void test2fail(UUID u) {
11+
u.clockSequence(); // should report an error, because u may not be time-based
12+
}
13+
void test3(UUID u) {
14+
if (u.version() == 1) {
15+
u.node(); // should be OK, because u is time-based
16+
}
17+
}
18+
void test4fail(UUID u) {
19+
if (u.version() == 2) {
20+
u.timestamp(); // should report an error, because u is not time-based -- but I don't get an error.
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)