Class LiteralImpl
- java.lang.Object
-
- org.apache.commons.rdf.simple.LiteralImpl
-
- All Implemented Interfaces:
Literal,RDFTerm,SimpleRDF.SimpleRDFTerm
final class LiteralImpl extends java.lang.Object implements Literal, SimpleRDF.SimpleRDFTerm
A simple implementation of Literal.
-
-
Field Summary
Fields Modifier and Type Field Description private IRIdataTypeprivate java.lang.StringlanguageTagprivate java.lang.StringlexicalFormprivate static java.lang.StringQUOTE
-
Constructor Summary
Constructors Constructor Description LiteralImpl(java.lang.String literal)LiteralImpl(java.lang.String literal, java.lang.String languageTag)LiteralImpl(java.lang.String lexicalForm, IRI dataType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Check it this Literal is equal to another Literal.IRIgetDatatype()The IRI identifying the datatype that determines how the lexical form maps to a literal value.java.util.Optional<java.lang.String>getLanguageTag()If and only if the datatype IRI is http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, the language tag for this Literal is a non-empty language tag as defined by BCP47.
If the datatype IRI is not http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, this method must returnOptional.empty().java.lang.StringgetLexicalForm()The lexical form of this literal, represented by a Unicode string.inthashCode()Calculate a hash code for this Literal.private static java.lang.StringlowerCase(java.lang.String langTag)java.lang.StringntriplesString()Return the term serialised as specified by the RDF-1.1 N-Triples Canonical form.java.lang.StringtoString()
-
-
-
Field Detail
-
QUOTE
private static final java.lang.String QUOTE
- See Also:
- Constant Field Values
-
dataType
private final IRI dataType
-
languageTag
private final java.lang.String languageTag
-
lexicalForm
private final java.lang.String lexicalForm
-
-
Constructor Detail
-
LiteralImpl
public LiteralImpl(java.lang.String literal)
-
LiteralImpl
public LiteralImpl(java.lang.String lexicalForm, IRI dataType)
-
LiteralImpl
public LiteralImpl(java.lang.String literal, java.lang.String languageTag)
-
-
Method Detail
-
getDatatype
public IRI getDatatype()
Description copied from interface:LiteralThe IRI identifying the datatype that determines how the lexical form maps to a literal value. If the datatype IRI is http://www.w3.org/1999/02/22-rdf-syntax-ns#langString,Literal.getLanguageTag()must not returnOptional.empty(), and it must return a valid BCP47 language tag.- Specified by:
getDatatypein interfaceLiteral- Returns:
- The datatype IRI for this literal.
- See Also:
- RDF-1.1 Literal datatype IRI
-
getLanguageTag
public java.util.Optional<java.lang.String> getLanguageTag()
Description copied from interface:LiteralIf and only if the datatype IRI is http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, the language tag for this Literal is a non-empty language tag as defined by BCP47.
If the datatype IRI is not http://www.w3.org/1999/02/22-rdf-syntax-ns#langString, this method must returnOptional.empty().The value space of language tags is always in lower case; although RDF implementations MAY convert all language tags to lower case, safe comparisons of language tags should be done using
String.toLowerCase(Locale)with the localeLocale.ROOT.Implementation note: If your application requires
Serializableobjects, it is best not to store anOptionalin a field. It is recommended to useOptional.ofNullable(Object)to create the return value for this method.- Specified by:
getLanguageTagin interfaceLiteral- Returns:
- The
Optionallanguage tag for this literal. IfOptional.isPresent()returns true, the value returned byOptional.get()must be a non-empty language tag string conforming to BCP47. - See Also:
- RDF-1.1 Literal language tag
-
getLexicalForm
public java.lang.String getLexicalForm()
Description copied from interface:LiteralThe lexical form of this literal, represented by a Unicode string.- Specified by:
getLexicalFormin interfaceLiteral- Returns:
- The lexical form of this literal.
- See Also:
- RDF-1.1 Literal lexical form
-
ntriplesString
public java.lang.String ntriplesString()
Description copied from interface:RDFTermReturn the term serialised as specified by the RDF-1.1 N-Triples Canonical form.- Specified by:
ntriplesStringin interfaceRDFTerm- Returns:
- The term serialised as RDF-1.1 N-Triples.
- See Also:
- RDF-1.1 N-Triples Canonical form
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
Description copied from interface:LiteralCalculate a hash code for this Literal.The returned hash code MUST be equal to the result of
Objects.hash(Object...)with the argumentsLiteral.getLexicalForm(),Literal.getDatatype(),Literal.getLanguageTag().map(s->s.toLowerString(Locale.ROOT)).This method MUST be implemented in conjunction with
Literal.equals(Object)so that two equal Literals produce the same hash code.
-
lowerCase
private static java.lang.String lowerCase(java.lang.String langTag)
-
equals
public boolean equals(java.lang.Object obj)
Description copied from interface:LiteralCheck it this Literal is equal to another Literal.Literal term equality: Two literals are term-equal (the same RDF literal) if and only if the two lexical forms, the two datatype IRIs, and the two language tags (if any) compare equal, character by character. Thus, two literals can have the same value without being the same RDF term.
As the value space for language tags is lower-space, if they are present, they MUST be compared character by character using the equivalent ofString.toLowerCase(java.util.Locale)with the localeLocale.ROOT.Implementations MUST also override
Literal.hashCode()so that two equal Literals produce the same hash code.
-
-