Skip to content

Package: IdentifierUtils

IdentifierUtils

nameinstructionbranchcomplexitylinemethod
IdentifierUtils()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
generateIdentifier(URI)
M: 0 C: 50
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.util;
16:
17: import java.net.URI;
18: import java.util.Random;
19:
20: /**
21: * Utility for automatic identifier generation.
22: */
23: public class IdentifierUtils {
24:
25: private static final Random RANDOM = new Random();
26:
27: /**
28: * Generates a (pseudo) random identifier based on the specified class URI.
29: * <p>
30: * The identifier consists of the class URI and then contains the string '_instance' and a random integer to ensure
31: * uniqueness.
32: *
33: * @param classUri Class URI used as identifier base
34: * @return Generated identifier
35: */
36: public static URI generateIdentifier(URI classUri) {
37:• if (classUri.getFragment() != null) {
38: return URI.create(classUri.toString() + "_instance" + RANDOM.nextInt());
39: } else {
40: String base = classUri.toString();
41:• if (base.endsWith("/")) {
42: return URI.create(base + "_instance" + RANDOM.nextInt());
43: } else {
44: return URI.create(base + "#instance" + RANDOM.nextInt());
45: }
46: }
47: }
48: }