org.nsdl.mptstore.rdf
Class Literal

java.lang.Object
  extended by org.nsdl.mptstore.rdf.Literal
All Implemented Interfaces:
Node, ObjectNode

public class Literal
extends java.lang.Object
implements ObjectNode

An RDF literal. A literal has a lexical component and optionally has either a language tag or a datatype (indicated by URIReference).

Author:
cwilper@cs.cornell.edu
See Also:
RDF Concepts and Abstract Syntax, Section 6.5

Constructor Summary
Literal(java.lang.String value)
          Construct a plain literal without a language tag.
Literal(java.lang.String value, java.lang.String language)
          Construct a plain literal with a language tag.
Literal(java.lang.String value, URIReference datatype)
          Construct a typed literal.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Tell whether this Node should be considered equivalent to the given object.
 URIReference getDatatype()
          Get the datatype, if any.
 java.lang.String getLanguage()
          Get the language tag, if any.
 java.lang.String getValue()
          Get the lexical value of the node.
 int hashCode()
          Return a hash code for this node.
 java.lang.String toString()
          Get an N-Triples string representing this node.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Literal

public Literal(java.lang.String value)
Construct a plain literal without a language tag.

Parameters:
value - The lexical value.

Literal

public Literal(java.lang.String value,
               java.lang.String language)
        throws java.text.ParseException
Construct a plain literal with a language tag. As per "RDF Concepts and Abstract Syntax", it will be normalized to lowercase.

Parameters:
value - The lexical value.
language - The language tag.
Throws:
java.text.ParseException - if the language tag is syntactically invalid.
See Also:
NTriplesUtil.validateLanguage(String)

Literal

public Literal(java.lang.String value,
               URIReference datatype)
Construct a typed literal.

Parameters:
value - The lexical value.
datatype - The datatype.
Method Detail

getLanguage

public java.lang.String getLanguage()
Get the language tag, if any.

Returns:
The language tag, or null if none.

getDatatype

public URIReference getDatatype()
Get the datatype, if any.

Returns:
The datatype, or null if none.

getValue

public java.lang.String getValue()
Get the lexical value of the node.

The lexical value of a URIReference node is the URI as a string.

The lexical value of a Literal node is a string representation of the value, and does not include the language or data type, if any.

Specified by:
getValue in interface Node
Returns:
the lexical value, never null.

toString

public java.lang.String toString()
Get an N-Triples string representing this node.

For URIReference nodes, this is <$uri>.

For Literal nodes, this is one of the following:

Note:

Specified by:
toString in interface Node
Overrides:
toString in class java.lang.Object
Returns:
the N-Triples representation of the node.
See Also:
RDF Test Cases, Section 3: N-Triples

equals

public boolean equals(java.lang.Object obj)
Tell whether this Node should be considered equivalent to the given object.

A URIReference node is equal to the given object if all of the following conditions are met:

A Literal node is equal to the given object if all of the following conditions are met:

Specified by:
equals in interface Node
Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare to this one.
Returns:
true if the objects are equal according to the rules above.

hashCode

public int hashCode()
Return a hash code for this node.

The hash code of a URIReference is the hash code of getURI(). The hash code of a Literal is the hash code of getValue().

Specified by:
hashCode in interface Node
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code.