Package org.eclipse.rdf4j.model

## Interface Literal

- All Superinterfaces:
    `Serializable`, `Value`
  All Known Implementing Classes:
    `AbstractLiteral`, `BooleanLiteral`, `BooleanMemLiteral`, `CalendarLiteral`, `CalendarMemLiteral`, `DecimalLiteral`, `DecimalMemLiteral`, `IntegerLiteral`, `IntegerMemLiteral`, `MemLiteral`, `NativeLiteral`, `NumericLiteral`, `NumericMemLiteral`, `SimpleLiteral`

      public interface Literal
      extends Value

  An RDF-1.1 literal consisting of a label (the lexical value), a datatype, and optionally a language tag.

  Value accessor methods (for instance, `booleanValue()`) map literal lexical values conforming to the syntax of a supported XML Schema 1.1 datatype to a corresponding Java object.

  Author:
    Arjohn Kampman
  See Also:
    RDF-1.1 Concepts and Abstract Syntax, RDF 1.1 Concepts and Abstract Syntax - §5.1 The XML Schema Built-in Datatypes, XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `booleanValue()` | Returns the boolean value of this literal.
    `byte` | `byteValue()` | Returns the byte value of this literal.
    `XMLGregorianCalendar` | `calendarValue()` | Returns the `XMLGregorianCalendar` value of this literal.
    `BigDecimal` | `decimalValue()` | Returns the decimal value of this literal.
    `double` | `doubleValue()` | Returns the double value of this literal.
    `boolean` | `equals​(Object other)` | Compares this literal to another object.
    `float` | `floatValue()` | Returns the float value of this literal.
    `IRI` | `getDatatype()` | Gets the datatype for this literal.
    `String` | `getLabel()` | Gets the label (the lexical value) of this literal.
    `Optional<String>` | `getLanguage()` | Gets the language tag for this literal, normalized to lower case.
    `int` | `hashCode()` | Computes the hash code of this literal.
    `BigInteger` | `integerValue()` | Returns the integer value of this literal.
    `int` | `intValue()` | Returns the int value of this literal.
    `default boolean` | `isLiteral()` | Check if the object is an instance of the given type.
    `long` | `longValue()` | Returns the long value of this literal.
    `short` | `shortValue()` | Returns the short value of this literal.
    `default TemporalAccessor` | `temporalAccessorValue()` | Retrieves the `temporal accessor` value of this literal.
    `default TemporalAmount` | `temporalAmountValue()` | Retrieves the `temporal amount` value of this literal.

    - ### Methods inherited from interface org.eclipse.rdf4j.model.Value

      `isBNode, isIRI, isResource, isTriple, stringValue`

- - ### Method Detail

    - #### isLiteral

          default boolean isLiteral()

      Description copied from interface: `Value`
      Check if the object is an instance of the given type. Typically 2x than using instanceof. For implementers: This default implementation is overridden in the repsective sub-interface.
      Specified by:
        `isLiteral` in interface `Value`
      Returns:
        true if instance of `Literal`

    - #### getLabel

          String getLabel()

      Gets the label (the lexical value) of this literal.
      Returns:
        The literal's label.

    - #### getLanguage

          Optional<String> getLanguage()

      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.

    - #### getDatatype

          IRI getDatatype()

      Gets the datatype for this literal.

      If `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.

    - #### booleanValue

          boolean booleanValue()

      Returns the boolean value of this literal.
      Returns:
        The boolean value of the literal.
      Throws:
        `IllegalArgumentException` - If the literal's label cannot be represented by a boolean .

    - #### byteValue

          byte byteValue()

      Returns the byte value of this literal.
      Returns:
        The byte value of the literal.
      Throws:
        `NumberFormatException` - If the literal cannot be represented by a byte.

    - #### shortValue

          short shortValue()

      Returns the short value of this literal.
      Returns:
        The short value of the literal.
      Throws:
        `NumberFormatException` - If the literal's label cannot be represented by a short.

    - #### intValue

          int intValue()

      Returns the int value of this literal.
      Returns:
        The int value of the literal.
      Throws:
        `NumberFormatException` - If the literal's label cannot be represented by a int.

    - #### longValue

          long longValue()

      Returns the long value of this literal.
      Returns:
        The long value of the literal.
      Throws:
        `NumberFormatException` - If the literal's label cannot be represented by to a long .

    - #### integerValue

          BigInteger integerValue()

      Returns the integer value of this literal.
      Returns:
        The integer value of the literal.
      Throws:
        `NumberFormatException` - If the literal's label is not a valid integer.

    - #### decimalValue

          BigDecimal decimalValue()

      Returns the decimal value of this literal.
      Returns:
        The decimal value of the literal.
      Throws:
        `NumberFormatException` - If the literal's label is not a valid decimal.

    - #### floatValue

          float floatValue()

      Returns the float value of this literal.
      Returns:
        The float value of the literal.
      Throws:
        `NumberFormatException` - If the literal's label cannot be represented by a float.

    - #### doubleValue

          double doubleValue()

      Returns the double value of this literal.
      Returns:
        The double value of the literal.
      Throws:
        `NumberFormatException` - If the literal's label cannot be represented by a double.

    - #### temporalAccessorValue

          default TemporalAccessor temporalAccessorValue()
                                                  throws DateTimeException

      Retrieves the `temporal accessor` value of this literal.

      A temporal accessor representation can be given for literals whose label conforms to the syntax of the following XML Schema 1.1 date/time datatypes:

      - xsd:dateTime,
      - xsd:time,
      - xsd:date,
      - xsd:gYearMonth,
      - xsd:gYear,
      - xsd:gMonthDay,
      - xsd:gDay,
      - xsd:gMonth.

      Temporal accessor representations may be converted to specific `java.time` values like `OffsetDateTime` using target static factory methods, for instance `OffsetDateTime.from(literal.temporalAccessorValue())`.

      Note however that `java.time` doesn't include dedicated classes for some legal XML Schema date/time values, like offset dates (for instance, `2020-11-16+01:00`) and `xsd:gDay` (for instance, `---16`).

      Returns:
        the temporal accessor value of this literal
      Throws:
        `DateTimeException` - if this literal cannot be represented by a `TemporalAccessor` value
      Since:
        3.5.0
      See Also:
        The Java™ Tutorials – Trail: Date Time

    - #### temporalAmountValue

          default TemporalAmount temporalAmountValue()
                                              throws DateTimeException

      Retrieves the `temporal amount` value of this literal.

      A temporal amount representation can be given for literals whose label conforms to the syntax of the XML Schema 2 xsd:duration datatype.

      The adoption of the XML Schema 2 definition is a known deviation from the RDF 1.1 standard; well-formedness rules are relaxed to consider all duration components as optional and freely mixable.

      Temporal amount representations may be converted to specific `java.time` values like `Duration` using target static factory methods, for instance `Duration.from(literal.temporalAmountValue())`.

      Note however that `java.time` doesn't include dedicated classes for legal XML Schema duration values including both date and time components (for instance, `P1YT23H`).

      Returns:
        the temporal amount value of this literal
      Throws:
        `DateTimeException` - if this literal cannot be represented by a `TemporalAmount` value
      Since:
        3.5.0
      See Also:
        The Java™ Tutorials – Trail: Date Time

    - #### calendarValue

          XMLGregorianCalendar calendarValue()

      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.
      Returns:
        The calendar value of the literal.
      Throws:
        `IllegalArgumentException` - If the literal cannot be represented by a `XMLGregorianCalendar`.

    - #### equals

          boolean equals​(Object other)

      Compares this literal to another object.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `other` - 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

          int hashCode()

      Computes the hash code of this literal.
      Overrides:
        `hashCode` in class `Object`
      Returns:
        a hash code for this literal computed as `getLabel()``.hashCode()`