org.mulgara.mrg
Class Literal

java.lang.Object
  extended by org.mulgara.mrg.Literal
All Implemented Interfaces:
Comparable<Node>, Node, ObjectNode

public class Literal
extends Object
implements ObjectNode

A Literal node.


Field Summary
static int TYPE_ID
          The type identifier for Literals
 
Constructor Summary
Literal(String text)
          Create a new simple literal.
Literal(String text, Object val, URI type)
          Create a structured typed literal.
Literal(String text, String lang)
          Create a language coded literal.
Literal(String text, String lang, URI type)
          General mechanism for creating a literal.
Literal(String text, URI type)
          Create a typed literal.
 
Method Summary
 int compareTo(Node o)
          Compares this object with the specified object for order.
 boolean equals(Object o)
          Equality method.
 String getLang()
          Gets the language code of this literal.
 String getText()
          Gets the text of this literal.
 URI getType()
          Gets the datatype of this literal.
 int getTypeId()
          A type identifier to distinguish from the other types of Node.
 Object getValue()
          Gets the typed data from this object.
 int hashCode()
          The hashcode, based on the label.
 Object toJava()
          Convert to a Java type.
 String toString()
          Represents this node as a string.
 boolean valueEquals(Literal l)
          Equality by value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_ID

public static final int TYPE_ID
The type identifier for Literals

See Also:
Constant Field Values
Constructor Detail

Literal

public Literal(String text)
Create a new simple literal.

Parameters:
text - The text of the literal.

Literal

public Literal(String text,
               URI type)
Create a typed literal.

Parameters:
text - The text of the literal.
type - The URI of the datatype.

Literal

public Literal(String text,
               Object val,
               URI type)
Create a structured typed literal.

Parameters:
text - The text of the literal.
val - The data value for the literal.
type - The URI of the datatype.

Literal

public Literal(String text,
               String lang)
Create a language coded literal.

Parameters:
text - The text of the literal.
lang - The language of the literal.

Literal

public Literal(String text,
               String lang,
               URI type)
General mechanism for creating a literal.

Parameters:
text - The text of the literal.
lang - The language of the literal.
type - The URI of the datatype.
Method Detail

getText

public String getText()
Gets the text of this literal.


getLang

public String getLang()
Gets the language code of this literal. May be null.


getType

public URI getType()
Gets the datatype of this literal. May be null.


getValue

public Object getValue()
Gets the typed data from this object.

Returns:
Just the lexical form

valueEquals

public boolean valueEquals(Literal l)
Equality by value. This is based on the datatype.


equals

public boolean equals(Object o)
Equality method. Based on the label.

Overrides:
equals in class Object

hashCode

public int hashCode()
The hashcode, based on the label.

Overrides:
hashCode in class Object

getTypeId

public int getTypeId()
A type identifier to distinguish from the other types of Node.

Specified by:
getTypeId in interface Node

compareTo

public int compareTo(Node o)
Compares this object with the specified object for order.

Specified by:
compareTo in interface Comparable<Node>
Parameters:
o - the object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

toString

public String toString()
Represents this node as a string.

Overrides:
toString in class Object

toJava

public Object toJava()
Convert to a Java type. This will pick the best type that it can, based on the type URI and the lexical representation. If unable to use anything else a string is returned.

Returns:
a Java object with the literal data in it.


Copyright © 2011. All Rights Reserved.