Skip to content

Package: IdentifierUtil

IdentifierUtil

nameinstructionbranchcomplexitylinemethod
IdentifierUtil()
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%
generateBlankNodeId()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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) 2017 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.jsonld.common;
16:
17: import java.util.Random;
18:
19: /**
20: * Allows to generate blank nodes for identifier-less instances.
21: * <p>
22: * Although objects in JSON-LD are not required to have id, some tools may have issues processing such data. In addition,
23: * multiple references to the same instance cannot be created when serializing the JSON-LD, as there is no identifier to
24: * reference.
25: */
26: public class IdentifierUtil {
27:
28: /**
29: * Prefix of a blank node identifier.
30: */
31: public static final String B_NODE_PREFIX = "_:";
32:
33: private static final Random RANDOM = new Random();
34:
35: /**
36: * Generates a (pseudo)random blank node identifier.
37: *
38: * @return Blank node identifier
39: */
40: public static String generateBlankNodeId() {
41: return B_NODE_PREFIX + RANDOM.nextInt(Integer.MAX_VALUE);
42: }
43: }