| 3340 | /// UUID u = new UUID().toString(); |
| 3341 | /// ``` |
| 3342 | static class UUID { |
| 3343 | |
| 3344 | /* |
| 3345 | * UUID - an implementation of the UUID specification for Codename One |
| 3346 | * by Francesco Galgani |
| 3347 | * |
| 3348 | * You can use this class as you want (public-domain license). |
| 3349 | */ |
| 3350 | private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; |
| 3351 | private static final Random randomTime = new Random(System.currentTimeMillis()); |
| 3352 | private static final Random randomClockSeqAndNode = new Random(getUniqueDeviceID()); |
| 3353 | |
| 3354 | private long time = 0l; |
| 3355 | private long clockSeqAndNode = 0l; |
| 3356 | |
| 3357 | /// Constructor for UUID, it uses the system clock and some device info |
| 3358 | /// as seeds for random data, that are enough for practical usage. |
| 3359 | public UUID() { |
| 3360 | this.time = randomTime.nextLong(); |
| 3361 | this.clockSeqAndNode = randomClockSeqAndNode.nextLong(); |
| 3362 | } |
| 3363 | |
| 3364 | /// Constructs a UUID from two `long` values. |
| 3365 | /// |
| 3366 | /// #### Parameters |
| 3367 | /// |
| 3368 | /// - `time`: the upper 64 bits |
| 3369 | /// |
| 3370 | /// - `clockSeqAndNode`: the lower 64 bits |
| 3371 | public UUID(long time, long clockSeqAndNode) { |
| 3372 | this.time = time; |
| 3373 | this.clockSeqAndNode = clockSeqAndNode; |
| 3374 | } |
| 3375 | |
| 3376 | private static String append(String a, short in) { |
| 3377 | return append(a, (long) in, 4); |
| 3378 | } |
| 3379 | |
| 3380 | private static String append(String a, int in) { |
| 3381 | return append(a, (long) in, 8); |
| 3382 | } |
| 3383 | |
| 3384 | private static String append(String a, long in, int length) { |
| 3385 | int lim = (length << 2) - 4; |
| 3386 | StringBuilder sb = new StringBuilder(a); |
| 3387 | while (lim >= 0) { |
| 3388 | sb.append((DIGITS[(byte) (in >> lim) & 0x0f])); |
| 3389 | lim -= 4; |
| 3390 | } |
| 3391 | return sb.toString(); |
| 3392 | } |
| 3393 | |
| 3394 | private static long getUniqueDeviceID() { |
| 3395 | long id = Preferences.get("CustomDeviceId__$", (long) -1); |
| 3396 | if (id == -1) { |
| 3397 | id = Preferences.get("DeviceId__$", (long) -1); |
| 3398 | } |
| 3399 | if (id == -1) { |
nothing calls this directly
no test coverage detected