Class Values


  • public class Values
    extends java.lang.Object
    Factory methods to quickly create Value objects ( IRI, Literal, BNode, and Triple) without having to create a ValueFactory first.

    Example usage:

     import static org.eclipse.rdf4j.model.util.Values.iri;
    
     ...
     IRI foo = iri("http://example.org/foo");
     

    Since:
    3.5.0
    See Also:
    Statements
    • Field Detail

      • VALUE_FACTORY

        private static final ValueFactory VALUE_FACTORY
        Internal shared value factory used for creating all values. We use a ValidatingValueFactory to ensure created values are syntactically legal.
    • Constructor Detail

      • Values

        private Values()
    • Method Detail

      • iri

        public static IRI iri​(java.lang.String iri)
                       throws java.lang.IllegalArgumentException
        Create a new IRI using the supplied iri string
        Parameters:
        iri - a string representing a valid (absolute) iri
        Returns:
        an IRI object for the supplied iri string.
        Throws:
        java.lang.NullPointerException - if the suppplied iri is null
        java.lang.IllegalArgumentException - if the supplied iri string can not be parsed as a legal IRI.
      • iri

        public static IRI iri​(ValueFactory vf,
                              java.lang.String iri)
                       throws java.lang.IllegalArgumentException
        Create a new IRI using the supplied iri string
        Parameters:
        vf - the ValueFactory to use for creation of the IRI.
        iri - a string representing a valid (absolute) iri
        Returns:
        an IRI object for the supplied iri string.
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
        java.lang.IllegalArgumentException - if the supplied iri string can not be parsed as a legal IRI by the supplied ValueFactory .
      • iri

        public static IRI iri​(java.lang.String namespace,
                              java.lang.String localName)
                       throws java.lang.IllegalArgumentException
        Create a new IRI using the supplied namespace name and local name
        Parameters:
        namespace - the IRI's namespace name
        localName - the IRI's local name
        Returns:
        an IRI object for the supplied IRI namespace name and localName.
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
        java.lang.IllegalArgumentException - if the supplied iri string can not be parsed as a legal IRI.
      • iri

        public static IRI iri​(Namespace namespace,
                              java.lang.String localName)
                       throws java.lang.IllegalArgumentException
        Create a new IRI using the supplied Namespace and local name
        Parameters:
        namespace - the IRI's Namespace
        localName - the IRI's local name
        Returns:
        an IRI object for the supplied IRI namespace and localName.
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
        java.lang.IllegalArgumentException - if the supplied iri string can not be parsed as a legal IRI.
        Since:
        3.6.0
      • iri

        public static IRI iri​(java.lang.Iterable<Namespace> namespaces,
                              java.lang.String prefixedName)
                       throws java.lang.IllegalArgumentException
        Create a new IRI from a supplied prefixed name, using the supplied namespaces
        Parameters:
        namespaces - the Namespaces from which to find the correct namespace to map the prefixed name to
        prefixedName - a prefixed name that is a shorthand for a full iri, using syntax form prefix:localName. For example, rdf:type is a prefixed name where rdf is the prefix. If the correct Namespace definition is also supplied this expands to the full namespace name http://www.w3.org/1999/02/22-rdf-syntax-ns#, leading to a full IRI http://www.w3.org/1999/02/22-rdf-syntax-ns#type.
        Returns:
        an IRI object for the supplied IRI namespace and localName.
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
        java.lang.IllegalArgumentException - if the supplied prefixed name can not be transformed to a legal IRI.
        Since:
        3.6.0
      • iri

        public static IRI iri​(ValueFactory vf,
                              java.lang.String namespace,
                              java.lang.String localName)
                       throws java.lang.IllegalArgumentException
        Create a new IRI using the supplied namespace and local name
        Parameters:
        vf - the ValueFactory to use for creation of the IRI.
        namespace - the IRI's namespace
        localName - the IRI's local name
        Returns:
        an IRI object for the supplied IRI namespace and localName.
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
        java.lang.IllegalArgumentException - if the supplied iri string can not be parsed as a legal IRI by the supplied ValueFactory
      • bnode

        public static BNode bnode()
        Creates a new BNode
        Returns:
        a new BNode
      • bnode

        public static BNode bnode​(ValueFactory vf)
        Creates a new BNode
        Parameters:
        vf - the ValueFactory to use for creation of the BNode
        Returns:
        a new BNode
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
      • bnode

        public static BNode bnode​(java.lang.String nodeId)
                           throws java.lang.IllegalArgumentException
        Creates a new BNode with the supplied node identifier.
        Parameters:
        nodeId - the node identifier
        Returns:
        a new BNode
        Throws:
        java.lang.NullPointerException - if the supplied node identifier is null.
        java.lang.IllegalArgumentException - if the supplied node identifier is not valid
      • bnode

        public static BNode bnode​(ValueFactory vf,
                                  java.lang.String nodeId)
                           throws java.lang.IllegalArgumentException
        Creates a new BNode with the supplied node identifier.
        Parameters:
        vf - the ValueFactory to use for creation of the BNode
        nodeId - the node identifier
        Returns:
        a new BNode
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
        java.lang.IllegalArgumentException - if the supplied node identifier is not valid
      • literal

        public static Literal literal​(java.lang.String lexicalValue)
        Creates a new Literal with the supplied lexical value.
        Parameters:
        lexicalValue - the lexical value for the literal
        Returns:
        a new Literal of type XSD.STRING
        Throws:
        java.lang.NullPointerException - if the supplied lexical value is null.
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.lang.String lexicalValue)
        Creates a new Literal with the supplied lexical value.
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        lexicalValue - the lexical value for the literal
        Returns:
        a new Literal of type XSD.STRING
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
      • literal

        public static Literal literal​(java.lang.String lexicalValue,
                                      java.lang.String languageTag)
        Creates a new Literal with the supplied lexical value.
        Parameters:
        lexicalValue - the lexical value for the literal
        languageTag - the language tag for the literal.
        Returns:
        a new Literal of type RDF.LANGSTRING
        Throws:
        java.lang.NullPointerException - if the supplied lexical value or language tag is null.
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.lang.String lexicalValue,
                                      java.lang.String languageTag)
        Creates a new Literal with the supplied lexical value.
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        lexicalValue - the lexical value for the literal
        languageTag - the language tag for the literal.
        Returns:
        a new Literal of type RDF.LANGSTRING
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null
      • literal

        public static Literal literal​(java.lang.String lexicalValue,
                                      IRI datatype)
                               throws java.lang.IllegalArgumentException
        Creates a new Literal with the supplied lexical value and datatype.
        Parameters:
        lexicalValue - the lexical value for the literal
        datatype - the datatype IRI
        Returns:
        a new Literal with the supplied lexical value and datatype
        Throws:
        java.lang.NullPointerException - if the supplied lexical value or datatype is null.
        java.lang.IllegalArgumentException - if the supplied lexical value is not valid for the given datatype
      • literal

        public static Literal literal​(java.lang.String lexicalValue,
                                      CoreDatatype datatype)
                               throws java.lang.IllegalArgumentException
        Creates a new Literal with the supplied lexical value and datatype.
        Parameters:
        lexicalValue - the lexical value for the literal
        datatype - the CoreDatatype
        Returns:
        a new Literal with the supplied lexical value and datatype
        Throws:
        java.lang.NullPointerException - if the supplied lexical value or datatype is null.
        java.lang.IllegalArgumentException - if the supplied lexical value is not valid for the given datatype
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.lang.String lexicalValue,
                                      IRI datatype)
                               throws java.lang.IllegalArgumentException
        Creates a new Literal with the supplied lexical value and datatype.
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        lexicalValue - the lexical value for the literal
        datatype - the datatype IRI
        Returns:
        a new Literal with the supplied lexical value and datatype
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
        java.lang.IllegalArgumentException - if the supplied lexical value is not valid for the given datatype
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.lang.String lexicalValue,
                                      CoreDatatype datatype)
                               throws java.lang.IllegalArgumentException
        Creates a new Literal with the supplied lexical value and datatype.
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        lexicalValue - the lexical value for the literal
        datatype - the CoreDatatype
        Returns:
        a new Literal with the supplied lexical value and datatype
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
        java.lang.IllegalArgumentException - if the supplied lexical value is not valid for the given datatype
      • literal

        public static Literal literal​(boolean booleanValue)
        Creates a new Literal with the supplied boolean value
        Parameters:
        booleanValue - a boolean value
        Returns:
        a Literal of type XSD.BOOLEAN with the supplied value
      • literal

        public static Literal literal​(ValueFactory vf,
                                      boolean booleanValue)
        Creates a new Literal with the supplied boolean value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        booleanValue - a boolean value
        Returns:
        a Literal of type XSD.BOOLEAN with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(byte byteValue)
        Creates a new Literal with the supplied byte value
        Parameters:
        byteValue - a byte value
        Returns:
        a Literal of type XSD.BYTE with the supplied value
      • literal

        public static Literal literal​(ValueFactory vf,
                                      byte byteValue)
        Creates a new Literal with the supplied byte value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        byteValue - a byte value
        Returns:
        a Literal of type XSD.BYTE with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(short shortValue)
        Creates a new Literal with the supplied short value
        Parameters:
        shortValue - a short value
        Returns:
        a Literal of type XSD.SHORT with the supplied value
      • literal

        public static Literal literal​(ValueFactory vf,
                                      short shortValue)
        Creates a new Literal with the supplied short value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        shortValue - a short value
        Returns:
        a Literal of type XSD.SHORT with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(int intValue)
        Creates a new Literal with the supplied int value
        Parameters:
        intValue - an int value
        Returns:
        a Literal of type XSD.INT with the supplied value
      • literal

        public static Literal literal​(ValueFactory vf,
                                      int intValue)
        Creates a new Literal with the supplied int value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        intValue - an int value
        Returns:
        a Literal of type XSD.INT with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(long longValue)
        Creates a new Literal with the supplied long value
        Parameters:
        longValue - a long value
        Returns:
        a Literal of type XSD.LONG with the supplied value
      • literal

        public static Literal literal​(ValueFactory vf,
                                      long longValue)
        Creates a new Literal with the supplied long value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        longValue - a long value
        Returns:
        a Literal of type XSD.LONG with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(float floatValue)
        Creates a new Literal with the supplied float value
        Parameters:
        floatValue - a float value
        Returns:
        a Literal of type XSD.FLOAT with the supplied value
      • literal

        public static Literal literal​(ValueFactory vf,
                                      float floatValue)
        Creates a new Literal with the supplied float value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        floatValue - a float value
        Returns:
        a Literal of type XSD.FLOAT with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(double doubleValue)
        Creates a new Literal with the supplied double value
        Parameters:
        doubleValue - a double value
        Returns:
        a Literal of type XSD.DOUBLE with the supplied value
      • literal

        public static Literal literal​(ValueFactory vf,
                                      double doubleValue)
        Creates a new Literal with the supplied double value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        doubleValue - a double value
        Returns:
        a Literal of type XSD.DOUBLE with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(java.math.BigDecimal bigDecimal)
        Creates a new Literal with the supplied BigDecimal value
        Parameters:
        bigDecimal - a BigDecimal value
        Returns:
        a Literal of type XSD.DECIMAL with the supplied value
        Throws:
        java.lang.NullPointerException - if the supplied bigDecimal is null.
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.math.BigDecimal bigDecimal)
        Creates a new Literal with the supplied BigDecimal value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        bigDecimal - a BigDecimal value
        Returns:
        a Literal of type XSD.DECIMAL with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(java.math.BigInteger bigInteger)
        Creates a new Literal with the supplied BigInteger value
        Parameters:
        bigInteger - a BigInteger value
        Returns:
        a Literal of type XSD.INTEGER with the supplied value
        Throws:
        java.lang.NullPointerException - if the supplied bigInteger is null.
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.math.BigInteger bigInteger)
        Creates a new Literal with the supplied BigInteger value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        bigInteger - a BigInteger value
        Returns:
        a Literal of type XSD.INTEGER with the supplied value
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
      • literal

        public static Literal literal​(java.time.temporal.TemporalAccessor value)
                               throws java.lang.IllegalArgumentException
        Creates a new Literal with the supplied TemporalAccessor value
        Parameters:
        value - a TemporalAccessor value.
        Returns:
        a Literal with the supplied calendar value and the appropriate XSD date/time datatype for the specific value.
        Throws:
        java.lang.NullPointerException - if the supplied TemporalAccessor value is null.
        java.lang.IllegalArgumentException - if value cannot be represented by an XML Schema date/time datatype
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.time.temporal.TemporalAccessor value)
                               throws java.lang.IllegalArgumentException
        Creates a new Literal with the supplied TemporalAccessor value
        Parameters:
        vf - the ValueFactory to use for creation of the Literal
        value - a TemporalAccessor value.
        Returns:
        a Literal with the supplied calendar value and the appropriate XSD date/time datatype for the specific value.
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null..
        java.lang.IllegalArgumentException - if value cannot be represented by an XML Schema date/time datatype
      • literal

        public static Literal literal​(java.lang.Object object)
        Creates a new typed Literal out of the supplied object, mapping the runtime type of the object to the appropriate XSD datatype. If no mapping is available, the method returns a literal with the string representation of the supplied object as the value, and XSD.STRING as the datatype.

        Recognized types are Boolean, Byte, Double, Float, Integer, Long, Short, XMLGregorianCalendar , TemporalAccessor and Date.

        Parameters:
        object - an object to be converted to a typed literal.
        Returns:
        a typed literal representation of the supplied object.
        Throws:
        java.lang.NullPointerException - if the input parameter is null..
      • literal

        public static Literal literal​(java.lang.Object object,
                                      boolean failOnUnknownType)
        Creates a new typed Literal out of the supplied object, mapping the runtime type of the object to the appropriate XSD datatype.

        Recognized types are Boolean, Byte, Double, Float, BigDecimal, Integer, BigInteger, Long, Short, XMLGregorianCalendar, TemporalAccessor, TemporalAmpount and Date.

        Parameters:
        object - an object to be converted to a typed literal.
        failOnUnknownType - If no mapping is available and failOnUnknownType is false the method returns a literal with the string representation of the supplied object as the value, and XSD.STRING as the datatype. If set to true the method throws an IllegalArgumentException if no mapping available.
        Returns:
        a typed literal representation of the supplied object.
        Throws:
        java.lang.NullPointerException - if the input parameter is null..
      • literal

        public static Literal literal​(ValueFactory vf,
                                      java.lang.Object object,
                                      boolean failOnUnknownType)
        Creates a new typed Literal out of the supplied object, mapping the runtime type of the object to the appropriate XSD datatype.

        Recognized types are Boolean, Byte, Double, Float, Integer, Long, Short, XMLGregorianCalendar, TemporalAccessor and Date.

        Parameters:
        valueFactory - the ValueFactoryto use for creation of the Literal
        object - an object to be converted to a typed literal.
        failOnUnknownType - If no mapping is available and failOnUnknownType is false the method returns a literal with the string representation of the supplied object as the value, and XSD.STRING as the datatype. If set to true the method throws an IllegalArgumentException if no mapping available.
        Returns:
        a typed literal representation of the supplied object.
        Throws:
        java.lang.NullPointerException - if any of the input parameters is null.
        java.lang.IllegalArgumentException - if failOnUnknownType is set to true and the runtime type of the supplied object could not be mapped.
      • triple

        public static Triple triple​(Resource subject,
                                    IRI predicate,
                                    Value object)
        Creates a new RDF-star embedded triple with the supplied subject, predicate, and object.
        Parameters:
        subject - the Triple subject
        predicate - the Triple predicate
        object - the Triple object
        Returns:
        a Triple with the supplied subject, predicate, and object.
        Throws:
        java.lang.NullPointerException - if any of the supplied input parameters is null.
      • triple

        public static Triple triple​(ValueFactory vf,
                                    Resource subject,
                                    IRI predicate,
                                    Value object)
        Creates a new RDF-star embedded triple with the supplied subject, predicate, and object.
        Parameters:
        vf - the ValueFactory to use for creation of the Triple
        subject - the Triple subject
        predicate - the Triple predicate
        object - the Triple object
        Returns:
        a Triple with the supplied subject, predicate, and object.
        Throws:
        java.lang.NullPointerException - if any of the supplied input parameters is null.
      • triple

        public static Triple triple​(Statement statement)
        Creates a new RDF-star embedded triple using the subject, predicate and object from the supplied Statement.
        Parameters:
        statement - the Statement from which to construct a Triple
        Returns:
        a Triple with the same subject, predicate, and object as the supplied Statement.
        Throws:
        java.lang.NullPointerException - if statement is null.
      • triple

        public static Triple triple​(ValueFactory vf,
                                    Statement statement)
        Creates a new RDF-star embedded triple using the subject, predicate and object from the supplied Statement.
        Parameters:
        vf - the ValueFactory to use for creation of the Triple
        statement - the Statement from which to construct a Triple
        Returns:
        a Triple with the same subject, predicate, and object as the supplied Statement.
        Throws:
        java.lang.NullPointerException - if any of the supplied input parameters is null.
      • namespace

        public static Namespace namespace​(java.lang.String prefix,
                                          java.lang.String name)
        Create a new Namespace object.
        Parameters:
        prefix - the prefix associated with the namespace
        name - the namespace name (typically an IRI) for the namespace.
        Returns:
        a Namespace object.
        Since:
        3.6.0
      • createLiteralFromObject

        private static Literal createLiteralFromObject​(ValueFactory valueFactory,
                                                       java.lang.Object object,
                                                       boolean throwExceptionOnFailure)
                                                throws java.lang.IllegalArgumentException
        Creates a typed Literal out of the supplied object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping is available, the method throws an exception if the boolean parameter is true, or if it is false it returns a literal with the string representation of the supplied object as the value, and XSD.STRING as the datatype. Recognized types are Boolean, Byte, Double, Float, Integer, Long, Short, XMLGregorianCalendar , and Date.
        Parameters:
        valueFactory - The ValueFactory to use when creating the result.
        object - an object to be converted to a typed literal.
        throwExceptionOnFailure - If true throws a LiteralUtilException when the object is not recognised. If false it returns a string typed literal based on the objects toString method.
        Returns:
        a typed literal representation of the supplied object.
        Throws:
        java.lang.IllegalArgumentException - If the literal could not be created.
        java.lang.NullPointerException - If the object was null.