Class SimpleLiteral

java.lang.Object
org.eclipse.rdf4j.model.base.AbstractLiteral
org.eclipse.rdf4j.model.impl.SimpleLiteral
All Implemented Interfaces:
Serializable, Literal, Value
Direct Known Subclasses:
BooleanLiteral, CalendarLiteral, DecimalLiteral, IntegerLiteral, MemLiteral, NativeLiteral, NumericLiteral

public class SimpleLiteral extends AbstractLiteral
A simple default implementation of the Literal interface.
Author:
Arjohn Kampman, David Huynh
See Also:
  • Constructor Details

    • SimpleLiteral

      protected SimpleLiteral()
    • SimpleLiteral

      protected SimpleLiteral(String label)
      Creates a new plain literal with the supplied label.
      Parameters:
      label - The label for the literal, must not be null.
    • SimpleLiteral

      protected SimpleLiteral(String label, String language)
      Creates a new plain literal with the supplied label and language tag.
      Parameters:
      label - The label for the literal, must not be null.
      language - The language tag for the literal, must not be null and not be empty.
    • SimpleLiteral

      protected SimpleLiteral(String label, IRI datatype)
      Creates a new datatyped literal with the supplied label and datatype.
      Parameters:
      label - The label for the literal, must not be null.
      datatype - The datatype for the literal.
    • SimpleLiteral

      protected SimpleLiteral(String label, IRI datatype, CoreDatatype coreDatatype)
      Creates a new datatyped literal with the supplied label and datatype.
      Parameters:
      label - The label for the literal, must not be null.
      datatype - The datatype for the literal.
    • SimpleLiteral

      @Deprecated(since="4.0.0", forRemoval=true) protected SimpleLiteral(String label, XSD.Datatype datatype)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • SimpleLiteral

      protected SimpleLiteral(String label, CoreDatatype datatype)
  • Method Details

    • setLabel

      protected void setLabel(String label)
    • getLabel

      public String getLabel()
      Description copied from interface: Literal
      Gets the label (the lexical value) of this literal.
      Returns:
      The literal's label.
    • setLanguage

      protected void setLanguage(String language)
    • getLanguage

      public Optional<String> getLanguage()
      Description copied from interface: Literal
      Gets the language tag for this literal, normalized to lower case.
      Returns:
      The language tag for this literal, or Optional.empty() if it doesn't have one.
    • setDatatype

      protected void setDatatype(IRI datatype)
    • setDatatype

      protected void setDatatype(IRI datatype, CoreDatatype coreDatatype)
    • setDatatype

      @Deprecated(since="4.0.0", forRemoval=true) protected void setDatatype(XSD.Datatype datatype)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • setDatatype

      protected void setDatatype(CoreDatatype datatype)
    • getDatatype

      public IRI getDatatype()
      Description copied from interface: Literal
      Gets the datatype for this literal.

      If Literal.getLanguage() returns a non-empty value than this must return rdf:langString. If no datatype was assigned to this literal by the creator, then this method must return xsd:string.

      Returns:
      The datatype for this literal.
    • getXsdDatatype

      @Deprecated(since="4.0.0", forRemoval=true) public Optional<XSD.Datatype> getXsdDatatype()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getCoreDatatype() instead.
      Returns:
    • equals

      public boolean equals(Object o)
      Description copied from interface: Literal
      Compares this literal to another object.
      Specified by:
      equals in interface Literal
      Overrides:
      equals in class AbstractLiteral
      Parameters:
      o - the object to compare this literal to
      Returns:
      true, if the other object is an instance of Literal and if their labels, language tags and datatypes are equal
    • hashCode

      public int hashCode()
      Description copied from interface: Literal
      Computes the hash code of this literal.
      Specified by:
      hashCode in interface Literal
      Overrides:
      hashCode in class AbstractLiteral
      Returns:
      a hash code for this literal computed as Literal.getLabel().hashCode()
    • toString

      public String toString()
      Returns the label of the literal with its language or datatype. Note that this method does not escape the quoted label.
      Overrides:
      toString in class AbstractLiteral
      See Also:
    • stringValue

      public String stringValue()
      Description copied from interface: Value
      Returns the String-value of a Value object. This returns either a Literal's label, a IRI's URI or a BNode's ID.
      Specified by:
      stringValue in interface Value
      Overrides:
      stringValue in class AbstractLiteral
    • booleanValue

      public boolean booleanValue()
      Description copied from interface: Literal
      Returns the boolean value of this literal.
      Specified by:
      booleanValue in interface Literal
      Overrides:
      booleanValue in class AbstractLiteral
      Returns:
      The boolean value of the literal.
    • byteValue

      public byte byteValue()
      Description copied from interface: Literal
      Returns the byte value of this literal.
      Specified by:
      byteValue in interface Literal
      Overrides:
      byteValue in class AbstractLiteral
      Returns:
      The byte value of the literal.
    • shortValue

      public short shortValue()
      Description copied from interface: Literal
      Returns the short value of this literal.
      Specified by:
      shortValue in interface Literal
      Overrides:
      shortValue in class AbstractLiteral
      Returns:
      The short value of the literal.
    • intValue

      public int intValue()
      Description copied from interface: Literal
      Returns the int value of this literal.
      Specified by:
      intValue in interface Literal
      Overrides:
      intValue in class AbstractLiteral
      Returns:
      The int value of the literal.
    • longValue

      public long longValue()
      Description copied from interface: Literal
      Returns the long value of this literal.
      Specified by:
      longValue in interface Literal
      Overrides:
      longValue in class AbstractLiteral
      Returns:
      The long value of the literal.
    • floatValue

      public float floatValue()
      Description copied from interface: Literal
      Returns the float value of this literal.
      Specified by:
      floatValue in interface Literal
      Overrides:
      floatValue in class AbstractLiteral
      Returns:
      The float value of the literal.
    • doubleValue

      public double doubleValue()
      Description copied from interface: Literal
      Returns the double value of this literal.
      Specified by:
      doubleValue in interface Literal
      Overrides:
      doubleValue in class AbstractLiteral
      Returns:
      The double value of the literal.
    • integerValue

      public BigInteger integerValue()
      Description copied from interface: Literal
      Returns the integer value of this literal.
      Specified by:
      integerValue in interface Literal
      Overrides:
      integerValue in class AbstractLiteral
      Returns:
      The integer value of the literal.
    • decimalValue

      public BigDecimal decimalValue()
      Description copied from interface: Literal
      Returns the decimal value of this literal.
      Specified by:
      decimalValue in interface Literal
      Overrides:
      decimalValue in class AbstractLiteral
      Returns:
      The decimal value of the literal.
    • calendarValue

      public XMLGregorianCalendar calendarValue()
      Description copied from interface: Literal
      Returns the XMLGregorianCalendar value of this literal. A calendar representation can be given for literals whose label conforms to the syntax of the following XML Schema datatypes: dateTime, time, date, gYearMonth, gMonthDay, gYear, gMonth or gDay.
      Specified by:
      calendarValue in interface Literal
      Overrides:
      calendarValue in class AbstractLiteral
      Returns:
      The calendar value of the literal.
    • getCoreDatatype

      public CoreDatatype getCoreDatatype()
      Description copied from interface: Literal
      CoreDatatype is an interface for natively supported datatypes in RDF4J. This includes, among others, the XML Schema datatypes and rdf:langString. CoreDatatypes are implemented as enums and more performant and convenient to work with than IRI-based datatypes. The constant {@link CoreDatatype#NONE)} is used to represent a datatype that is not one of the supported core datatypes.
      Returns:
      The CoreDatatype or {@link CoreDatatype#NONE)} if the datatype matches none of the core datatypes. This method will not return null.