Interface Literal

  • All Superinterfaces:
    java.io.Serializable, Value
    All Known Implementing Classes:
    ArrayLiteral

    public interface Literal
    extends Value

    A literal value in an RDF graph

    Since:
    1.0
    Version:
    1.0
    Author:
    Michael Grove
    See Also:
    RDF Literal
    • Field Detail

      • STRICT_TYPES

        static final boolean STRICT_TYPES
        System setting that controls whether the casting methods of Literal such as intValue(Literal) are strict about the conversion. When `true`, if you try to get the `int` value of `"5"^^xsd:string` it will throw a NumberFormatException because the datatype of the `Literal` is incompatible with `int`. If `false` the label() will be used and passed to, in this example, `Integer.parseInt(String) which still may throw a `NumberFormatException` if the value of the `Literal` is not a valid numeric value. The default value is `false`.
    • Method Detail

      • label

        @Nonnull
        java.lang.String label()
        The lexical value of the literal
        Returns:
        the lexical value
      • lang

        @Nonnull
        default java.util.Optional<java.lang.String> lang()
        Optionally, the language of the lexical value of the `Literal`. When present, the datatype() is RDF.LANG_STRING.
        Returns:
        the language of the literal
        See Also:
        RDF Language
      • datatypeIRI

        @Nonnull
        default IRI datatypeIRI()
        The IRI of the Datatype of the `Literal`. Often, this is syntactic sugar for `datatype().iri()` however, in the case where it is a user defined datatype, eg Datatype.UDF this will return the specific IRI of the datatype.
        Returns:
        the datatype IRI of the lexical value
      • datatype

        @Nonnull
        Datatype datatype()
        The datatype of the `Literal`. Some serializations of RDF use a "simple literal" which is a literal with no explicit datatype. That is just syntactic sugar for `xsd:string` typed literals.
        Returns:
        the Datatype
      • str

        @Nonnull
        static java.lang.String str​(@Nonnull
                                    Literal theLiteral)
        Return the `String` serialization of the Literal
        Parameters:
        theLiteral - the `Literal` to serialize
        Returns:
        the serialized `Literal`
      • isLanguageLiteral

        static boolean isLanguageLiteral​(@Nonnull
                                         Literal theLiteral)
        Sugar for `Literal.lang().isPresent()`
        Parameters:
        theLiteral - the literal
        Returns:
        whether or not it's a language tagged literal
      • booleanValue

        static boolean booleanValue​(@Nonnull
                                    Literal theLiteral)
        Get the value of the Literal as a `boolean`.
        Parameters:
        theLiteral - the literal
        Returns:
        the value
        See Also:
        BooleanLiteral
      • calendarValue

        static javax.xml.datatype.XMLGregorianCalendar calendarValue​(@Nonnull
                                                                     Literal theLiteral)
        Get the value of the Literal as a calendar.
        Parameters:
        theLiteral - the literal
        Returns:
        the value
        Throws:
        java.lang.IllegalArgumentException - if the literal is not a calendar datatype
        See Also:
        CalendarLiteral, XMLDatatypes.isCalendarDatatype(Datatype)
      • xmlCalendarValue

        static XMLCalendar xmlCalendarValue​(@Nonnull
                                            Literal theLiteral)
        Get the value of the Literal as a calendar. Defers the creation of XMLGregorianCalendar if possible
        Parameters:
        theLiteral - the literal
        Returns:
        the value
        Throws:
        java.lang.IllegalArgumentException - if the literal is not a calendar datatype
        See Also:
        CalendarLiteral, XMLDatatypes.isCalendarDatatype(Datatype)
      • intValue

        static int intValue​(@Nonnull
                            Literal theLiteral)
      • byteValue

        static byte byteValue​(@Nonnull
                              Literal theLiteral)
      • shortValue

        static int shortValue​(@Nonnull
                              Literal theLiteral)
      • longValue

        static long longValue​(@Nonnull
                              Literal theLiteral)
      • durationValue

        @Nonnull
        static javax.xml.datatype.Duration durationValue​(@Nonnull
                                                         Literal theLiteral)
      • floatValue

        static float floatValue​(@Nonnull
                                Literal theLiteral)
        Get the value of the Literal as a `float`.
        Parameters:
        theLiteral - the literal
        Returns:
        the value
        Throws:
        java.lang.NumberFormatException - if the literal is not a numeric datatype
      • doubleValue

        static double doubleValue​(@Nonnull
                                  Literal theLiteral)
        Get the value of the Literal as a `double`.
        Parameters:
        theLiteral - the literal
        Returns:
        the value
        Throws:
        java.lang.NumberFormatException - if the literal is not a numeric datatype
      • integerValue

        static java.math.BigInteger integerValue​(@Nonnull
                                                 Literal theLiteral)
        Get the value of the Literal as a BigInteger.
        Parameters:
        theLiteral - the literal
        Returns:
        the value
        Throws:
        java.lang.NumberFormatException - if the literal is not a numeric datatype
      • decimalValue

        static java.math.BigDecimal decimalValue​(@Nonnull
                                                 Literal theLiteral)
        Get the value of the Literal as a BigDecimal.
        Parameters:
        theLiteral - the literal
        Returns:
        the value
        Throws:
        java.lang.NumberFormatException - if the literal is not a numeric datatype