]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.acr/src/org/argeo/api/acr/uuid/TimeUuidState.java
Working UUID factory
[lgpl/argeo-commons.git] / org.argeo.api.acr / src / org / argeo / api / acr / uuid / TimeUuidState.java
1 package org.argeo.api.acr.uuid;
2
3 import java.time.Instant;
4 import java.time.ZoneOffset;
5 import java.time.ZonedDateTime;
6
7 /**
8 * The state of a time based UUID generator, as described and discussed in
9 * section 4.2.1 of RFC4122.
10 *
11 * @see https://datatracker.ietf.org/doc/html/rfc4122#section-4.2.1
12 */
13 public interface TimeUuidState {
14
15 /** Start of the Gregorian time, used by time-based UUID (v1). */
16 final static Instant GREGORIAN_START = ZonedDateTime.of(1582, 10, 15, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
17
18 byte[] getNodeId();
19
20 long useTimestamp();
21
22 long getClockSequence();
23
24 static boolean isNoMacAddressNodeId(byte[] nodeId) {
25 return (nodeId[0] & 1) != 0;
26 }
27
28 static class Holder {
29 byte[] nodeId = new byte[6];
30 long lastTimestamp;
31 long clockSequence;
32
33 public byte[] getNodeId() {
34 return nodeId;
35 }
36
37 public void setNodeId(byte[] nodeId) {
38 this.nodeId = nodeId;
39 }
40
41 public long getLastTimestamp() {
42 return lastTimestamp;
43 }
44
45 public void setLastTimestamp(long lastTimestamp) {
46 this.lastTimestamp = lastTimestamp;
47 }
48
49 public long getClockSequence() {
50 return clockSequence;
51 }
52
53 public void setClockSequence(long clockSequence) {
54 this.clockSequence = clockSequence;
55 }
56
57 }
58 }