Skip to content

Package: IdGenerator

IdGenerator

nameinstructionbranchcomplexitylinemethod
generate()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial APInd implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.commons.model.id;
14:
15: import org.eclipse.kapua.commons.setting.system.SystemSetting;
16: import org.eclipse.kapua.commons.setting.system.SystemSettingKey;
17: import org.eclipse.kapua.commons.util.RandomUtils;
18:
19: import java.math.BigInteger;
20: import java.util.Random;
21:
22: /**
23: * Generates random identifier
24: *
25: * @since 1.0.0
26: */
27: public class IdGenerator {
28:
29: private static final Random RANDOM = RandomUtils.getInstance();
30: private static final int ID_SIZE = SystemSetting.getInstance().getInt(SystemSettingKey.KAPUA_KEY_SIZE);
31:
32: private IdGenerator() {
33: }
34:
35: /**
36: * Generate a {@link BigInteger} random value.<br>
37: * For more detail refer to: {@link SystemSettingKey#KAPUA_KEY_SIZE}
38: *
39: * @return
40: */
41: public static BigInteger generate() {
42: return new BigInteger(ID_SIZE, RANDOM);
43: }
44:
45: }