Skip to content

Package: Literal

Literal

nameinstructionbranchcomplexitylinemethod
Literal(String, String)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
equals(Object)
M: 29 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
from(String, String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDatatype()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getLexicalForm()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hashCode()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 0 C: 17
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) 2022 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.model;
16:
17: import java.io.Serializable;
18: import java.util.Objects;
19:
20: /**
21: * Represents an RDF literal consisting of a lexical form and datatype IRI.
22: * <p>
23: * To represent language-tagged string values, use {@link LangString}.
24: */
25: public class Literal implements Serializable {
26:
27: private final String lexicalForm;
28:
29: private final String datatype;
30:
31: public Literal(String lexicalForm, String datatype) {
32: this.lexicalForm = Objects.requireNonNull(lexicalForm);
33: this.datatype = Objects.requireNonNull(datatype);
34: }
35:
36: /**
37: * Gets the lexical form of this literal.
38: *
39: * @return String containing the lexical form
40: */
41: public String getLexicalForm() {
42: return lexicalForm;
43: }
44:
45: /**
46: * Gets the datatype identifier.
47: *
48: * @return String containing the datatype IRI
49: */
50: public String getDatatype() {
51: return datatype;
52: }
53:
54: @Override
55: public boolean equals(Object o) {
56:• if (this == o) {
57: return true;
58: }
59:• if (!(o instanceof Literal)) {
60: return false;
61: }
62: Literal literal = (Literal) o;
63:• return lexicalForm.equals(literal.lexicalForm) && datatype.equals(literal.datatype);
64: }
65:
66: @Override
67: public int hashCode() {
68: return Objects.hash(lexicalForm, datatype);
69: }
70:
71: @Override
72: public String toString() {
73: return "\"" + lexicalForm + "\"^^<" + datatype + ">";
74: }
75:
76: /**
77: * Creates a literal instance from the specified lexical form and datatype.
78: * <p>
79: * Convenience factory method alternative to constructor.
80: *
81: * @param lexicalForm Lexical form of the literal
82: * @param datatype Datatype of the literal
83: * @return Literal instance
84: */
85: public static Literal from(String lexicalForm, String datatype) {
86: return new Literal(lexicalForm, datatype);
87: }
88: }