-
Notifications
You must be signed in to change notification settings - Fork 14
/
Literal.java
74 lines (63 loc) · 1.87 KB
/
Literal.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cz.cvut.kbss.ontodriver.model;
import java.io.Serializable;
import java.util.Objects;
/**
* Represents an RDF literal consisting of a lexical form and datatype IRI.
* <p>
* To represent language-tagged string values, use {@link LangString}.
*/
public class Literal implements Serializable {
private final String lexicalForm;
private final String datatype;
public Literal(String lexicalForm, String datatype) {
this.lexicalForm = Objects.requireNonNull(lexicalForm);
this.datatype = Objects.requireNonNull(datatype);
}
/**
* Gets the lexical form of this literal.
*
* @return String containing the lexical form
*/
public String getLexicalForm() {
return lexicalForm;
}
/**
* Gets the datatype identifier.
*
* @return String containing the datatype IRI
*/
public String getDatatype() {
return datatype;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Literal)) {
return false;
}
Literal literal = (Literal) o;
return lexicalForm.equals(literal.lexicalForm) && datatype.equals(literal.datatype);
}
@Override
public int hashCode() {
return Objects.hash(lexicalForm, datatype);
}
@Override
public String toString() {
return "\"" + lexicalForm + "\"^^<" + datatype + ">";
}
/**
* Creates a literal instance from the specified lexical form and datatype.
* <p>
* Convenience factory method alternative to constructor.
*
* @param lexicalForm Lexical form of the literal
* @param datatype Datatype of the literal
* @return Literal instance
*/
public static Literal from(String lexicalForm, String datatype) {
return new Literal(lexicalForm, datatype);
}
}