]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/NodeIdSupplier.java
Fix manifest generation
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / NodeIdSupplier.java
1 package org.argeo.api.uuid;
2
3 import java.security.SecureRandom;
4 import java.util.function.Supplier;
5
6 /** A factory for node id base */
7 public interface NodeIdSupplier extends Supplier<Long> {
8 static long toNodeIdBase(byte[] node) {
9 assert node.length == 6;
10 return UuidFactory.LEAST_SIG_RFC4122_VARIANT | (node[0] & 0xFFL) //
11 | ((node[1] & 0xFFL) << 8) //
12 | ((node[2] & 0xFFL) << 16) //
13 | ((node[3] & 0xFFL) << 24) //
14 | ((node[4] & 0xFFL) << 32) //
15 | ((node[5] & 0xFFL) << 40); //
16 }
17
18 static boolean isNoMacAddressNodeId(byte[] nodeId) {
19 return (nodeId[0] & 1) != 0;
20 }
21
22 static byte[] randomNodeId() {
23 SecureRandom random = new SecureRandom();
24 byte[] nodeId = new byte[6];
25 random.nextBytes(nodeId);
26 return nodeId;
27 }
28 }