Class Values


  • public final class Values
    extends java.lang.Object

    Utility functions for creating and working with RDF values

    Since:
    1.0
    Version:
    1.0
    Author:
    Michael Grove
    • Field Detail

      • DEFAULT_GRAPH

        public static final IRI DEFAULT_GRAPH
        Special IRI representing the default (no) context.
      • LOCAL_GRAPHS

        public static final IRI LOCAL_GRAPHS
        Special IRI representing the union of the local (non-virtual) default graph and all local named graphs
      • NAMED_GRAPHS

        public static final IRI NAMED_GRAPHS
        Special IRI representing only local named graphs; this excludes the default graph
      • ALL_GRAPHS

        public static final IRI ALL_GRAPHS
        Special IRI representing the union of the local and virtual graphs
      • VIRTUAL_GRAPHS

        public static final IRI VIRTUAL_GRAPHS
        Special IRI representing the union of the virtual graphs
      • DATATYPE_FACTORY

        public static final javax.xml.datatype.DatatypeFactory DATATYPE_FACTORY
        Datatype factory that will be used for date/time literals. Cached to boost performance.
      • VIRTUAL_NAMESPACE

        public static final java.lang.String VIRTUAL_NAMESPACE
        Namespace reserved for virtual graph names
        See Also:
        Constant Field Values
    • Method Detail

      • namespace

        @Nonnull
        public static Namespace namespace​(@Nonnull
                                          java.lang.String thePrefix,
                                          @Nonnull
                                          java.lang.String theIRI)
        Create a Namespace
        Parameters:
        thePrefix - the prefix
        theIRI - the IRI
        Returns:
        the new `Namespace`
      • iri

        @Nonnull
        public static IRI iri​(@Nonnull
                              java.lang.String theNS,
                              @Nonnull
                              java.lang.String theLocalName)
        Create a new IRI from a namespace and a local name
        Parameters:
        theNS - the namespace IRI
        theLocalName - the local name
        Returns:
        the new `IRI`
      • iri

        @Nonnull
        public static IRI iri​(@Nonnull
                              java.lang.String theIRI)
        Create a new IRI
        Parameters:
        theIRI - the IRI string
        Returns:
        the new `IRI`
      • bnode

        @Nonnull
        public static BNode bnode()
        Create a new BNode
        Returns:
        the new `BNode`
      • bnode

        @Nonnull
        public static BNode bnode​(@Nonnull
                                  java.lang.String theId)
        Create a new BNode
        Parameters:
        theId - the id of the bnode
        Returns:
        the new `BNode`
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.lang.String theLabel)
        Create a new `xsd:string` Literal
        Parameters:
        theLabel - the label
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(boolean theValue)
        Create a new `xsd:boolean` Literal
        Parameters:
        theValue - the value
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(int theValue)
        Create a new `xsd:int` Literal
        Parameters:
        theValue - the value
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(long theValue)
        Create a new `xsd:long` Literal
        Parameters:
        theValue - the value
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(float theValue)
        Create a new `xsd:float` Literal
        Parameters:
        theValue - the value
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(double theValue)
        Create a new `xsd:double` Literal
        Parameters:
        theValue - the value
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(short theValue)
        Create a new `xsd:short` Literal
        Parameters:
        theValue - the value
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(byte theValue)
        Create a new `xsd:byte` Literal
        Parameters:
        theValue - the value
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.lang.String theLabel,
                                      @Nonnull
                                      IRI theDatatype)
        Create a new typed Literal
        Parameters:
        theLabel - the label of the literal
        theDatatype - the datatype
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.lang.String theLabel,
                                      @Nonnull
                                      java.lang.String theLanguage)
        Create a new language Literal
        Parameters:
        theLabel - the label of the literal
        theLanguage - the language of the literal
        Returns:
        the new `Literal`
      • literal

        @Nonnull
        public static Literal literal​(int theLabel,
                                      @Nonnull
                                      Datatype theDatatype)
        Create a new Literal
        Parameters:
        theLabel - the label of the literal value
        theDatatype - the datatype
        Returns:
        the literal
        Throws:
        java.lang.IllegalArgumentException - if the provided value `theLabel` is not syntactically correct wrt to its Datatype
      • literal

        @Nonnull
        public static Literal literal​(long theLabel,
                                      @Nonnull
                                      Datatype theDatatype)
        Create a new Literal
        Parameters:
        theLabel - the label of the literal value
        theDatatype - the datatype
        Returns:
        the literal
        Throws:
        java.lang.IllegalArgumentException - if the provided value `theLabel` is not syntactically correct wrt to its Datatype
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.lang.Number theNumber)
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.lang.String theLabel,
                                      @Nonnull
                                      Datatype theDatatype)
        Create a new Literal
        Parameters:
        theLabel - the label of the literal value
        theDatatype - the datatype
        Returns:
        the literal
        Throws:
        java.lang.NumberFormatException - if the literal is declared as a number, such as an `int` but is not syntactically correct.
        java.lang.IllegalArgumentException - if the provided value `theLabel` is not syntactically correct wrt to its Datatype
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.util.Date theDate)
        Create a new Literal for the given `Date` value.
        Parameters:
        theDate - the value of the literal
        Returns:
        the new literal
        See Also:
        CalendarLiteral
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.util.GregorianCalendar theDate)
        Create a new calendar based Literal.
        Parameters:
        theDate - the value of the literal
        Returns:
        the new literal
        See Also:
        CalendarLiteral
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      javax.xml.datatype.Duration theDuration)
        Create a Duration typed literal.
        Parameters:
        theDuration - the duration
        Returns:
        the new duration literal
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      javax.xml.datatype.Duration theDuration,
                                      @Nonnull
                                      IRI theDurationType)
        Create a Duration typed literal. Uses the datatype specified in the method; care should be used to ensure that it's one of the xsd duration types. If not, comparison results could be indeterminate or incorrect.
        Parameters:
        theDuration - the duration
        theDurationType - the duration datatype
        Returns:
        the new duration literal
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      javax.xml.datatype.XMLGregorianCalendar theCalendar)
        Create a new calendar based Literal.
        Parameters:
        theCalendar - the value of the literal
        Returns:
        the new literal
        See Also:
        CalendarLiteral
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      javax.xml.datatype.XMLGregorianCalendar theCalendar,
                                      @Nonnull
                                      Datatype theDatatype)
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      javax.xml.datatype.Duration theCalendar,
                                      @Nonnull
                                      Datatype theDatatype)
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.math.BigDecimal theBigDecimal)
      • literal

        @Nonnull
        public static Literal literal​(@Nonnull
                                      java.math.BigInteger theInt)
      • statement

        @Nonnull
        public static Statement statement​(@Nonnull
                                          Resource theSubject,
                                          @Nonnull
                                          IRI thePredicate,
                                          @Nonnull
                                          Value theObject)
        Create a new Statement in the default graph
        Parameters:
        theSubject - the subject of the statement
        thePredicate - the predicate of the statement
        theObject - the object of the statement
        Returns:
        the new `Statement`
      • isValid

        public static boolean isValid​(Literal theLiteral)
        Verifies that the given literal is valid. Checks if the supplied lexical value is valid for the given datatype. For language literals, it is checked if the language tag conforms to the RFC3066 spec.
        Parameters:
        theLiteral - the literal to validate
        Returns:
        true if it is a valid literal, false otherwise
      • isValid

        public static boolean isValid​(IRI theIRI)
        Verifies that the given IRI is valid.
        Parameters:
        theIRI - the IRI to validate
        Returns:
        true if it is a valid IRI, false otherwise
      • containsInvalidIRICharacters

        public static boolean containsInvalidIRICharacters​(java.lang.String theIRI)
      • containsLeadingOrTrailingWhitespace

        public static boolean containsLeadingOrTrailingWhitespace​(java.lang.String theIRI)
      • isValid

        public static boolean isValid​(Value theValue)
        Verifies that the given value is valid.
        Parameters:
        theValue - the value to validate
        Returns:
        true if it is a valid value, false otherwise
      • statement

        @Nonnull
        public static Statement statement​(@Nonnull
                                          Resource theSubject,
                                          @Nonnull
                                          IRI thePredicate,
                                          @Nonnull
                                          Value theObject,
                                          Resource theContext)
        Create a new Statement
        Parameters:
        theSubject - the subject of the statement
        thePredicate - the predicate of the statement
        theObject - the object of the statement
        theContext - the context of the statement. if the statement is intended to be in the default graph, DEFAULT_GRAPH should be used.
        Returns:
        the new `Statement`
      • isDefaultGraph

        public static boolean isDefaultGraph​(Resource theContext)
        Return whether or not the given Resource denotes the default graph
        Parameters:
        theContext - the graph
        Returns:
        `true` if the default graph, false otherwise
      • isVirtual

        public static boolean isVirtual​(Resource theContext)
        Return whether or not the resource represents a virtual graph (starts with VIRTUAL_NAMESPACE
      • isInDefaultGraph

        public static boolean isInDefaultGraph​(@Nonnull
                                               Statement theStmt)
        Return whether or not the given Statement is in the default graph
        Parameters:
        theStmt - the graph
        Returns:
        `true` if the default graph, false otherwise
      • isAll

        public static boolean isAll​(@Nonnull
                                    Resource theContext)
        Return whether or not the resource represents the meta-context ALL_GRAPHS
        Parameters:
        theContext - the context
        Returns:
        true if its ALL, false otherwise
      • isNamed

        public static boolean isNamed​(@Nonnull
                                      Resource theContext)
        Return whether or not the resource represents the meta-context NAMED_GRAPHS
        Parameters:
        theContext - the context
        Returns:
        true if its NAMED, false otherwise
      • resource

        public static Resource resource​(java.lang.String id)
        Treats IDs starting with "_:" as stable bnodes and creates BNode objects for them, otherwise creates IRIs.
        Parameters:
        id - resource ID
        Returns:
        IRI or bnode