org.eclipse.rdf4j.model.util

## Class GraphUtil

- java.lang.Object
- - org.eclipse.rdf4j.model.util.GraphUtil

- Deprecated.
  since 2.0. Use equivalent functionality in `Model` and `Models` instead.

      @Deprecated
      public class GraphUtil
      extends Object

  Utility methods for working with `Graph` objects. Note that since release 2.7.0, most of the functionality here is also available (in more convenient form) in the `Model` interface, which extends `Graph`.
  Author:
    Arjohn Kampman

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GraphUtil()` Deprecated.

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Iterator<Value>` | `getObjectIterator(Graph graph, Resource subj, IRI pred, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objects()` instead.
    `static Set<Value>` | `getObjects(Graph graph, Resource subj, IRI pred, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objects()` instead.
    `static Value` | `getOptionalObject(Graph graph, Resource subj, IRI pred, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectValue()` instead.
    `static Literal` | `getOptionalObjectLiteral(Graph graph, Resource subj, IRI pred)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectLiteral()` instead.
    `static Resource` | `getOptionalObjectResource(Graph graph, Resource subj, IRI pred)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectResource()` instead.
    `static IRI` | `getOptionalObjectURI(Graph graph, Resource subj, IRI pred)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectIRI()` instead.
    `static Resource` | `getOptionalSubject(Graph graph, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectResource()` instead.
    `static IRI` | `getOptionalSubjectURI(Graph graph, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectIRI()` instead.
    `static Iterator<Resource>` | `getSubjectIterator(Graph graph, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjects()` instead.
    `static Set<Resource>` | `getSubjects(Graph graph, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjects()` instead.
    `static Value` | `getUniqueObject(Graph graph, Resource subj, IRI pred, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectValue()` instead.
    `static Literal` | `getUniqueObjectLiteral(Graph graph, Resource subj, IRI pred)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectLiteral()` instead.
    `static Resource` | `getUniqueObjectResource(Graph graph, Resource subj, IRI pred)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectResource()` instead.
    `static IRI` | `getUniqueObjectURI(Graph graph, Resource subj, IRI pred)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectIRI()` instead.
    `static Resource` | `getUniqueSubject(Graph graph, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectResource()` instead.
    `static IRI` | `getUniqueSubjectURI(Graph graph, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectIRI()` instead.
    `static void` | `remove(Graph graph, Resource subj, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Model.remove(Resource, IRI, Value, Resource...)` instead.
    `static void` | `setUniqueObject(Graph graph, Resource subj, IRI pred, Value obj, Resource... contexts)` Deprecated. since 2.0. Use `Models.setProperty(Model, Resource, IRI, Value, Resource...)` instead.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### GraphUtil

          public GraphUtil()

      Deprecated.

  - ### Method Detail

    - #### getSubjectIterator

          @Deprecated
          public static Iterator<Resource> getSubjectIterator(Graph graph,
                                                                          IRI pred,
                                                                          Value obj,
                                                                          Resource... contexts)

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjects()` instead.
      Gets the subject of the statements with the specified predicate, object and (optionally) contexts from the supplied graph. Calling this method is equivalent to calling `graph.match(null, pred, obj, contexts)` and extracting the subjects of the matching statements from the returned iterator. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.

    - #### getSubjects

          @Deprecated
          public static Set<Resource> getSubjects(Graph graph,
                                                              IRI pred,
                                                              Value obj,
                                                              Resource... contexts)

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjects()` instead.
      Gets the subject of the statements with the specified predicate, object and (optionally) contexts from the supplied graph. Calling this method is equivalent to calling `graph.match(null, pred, obj, contexts)` and adding the subjects of the matching statements to a set. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.

    - #### getUniqueSubject

          @Deprecated
          public static Resource getUniqueSubject(Graph graph,
                                                              IRI pred,
                                                              Value obj,
                                                              Resource... contexts)
                                                       throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectResource()` instead.
      Gets the subject of the statement(s) with the specified predicate and object from the specified contexts in the supplied graph. The combination of predicate, object and contexts must match at least one statement. In case more than one statement matches -- for example statements from multiple contexts -- all these statements should have the same subject. A `GraphUtilException` is thrown if these conditions are not met. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.
      Returns:
        The subject of the matched statement(s).
      Throws:
        `GraphUtilException` - If the statements matched by the specified parameters do not have exactly one unique subject.

    - #### getUniqueSubjectURI

          @Deprecated
          public static IRI getUniqueSubjectURI(Graph graph,
                                                            IRI pred,
                                                            Value obj,
                                                            Resource... contexts)
                                                     throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectIRI()` instead.
      Utility method that casts the return value of `getUniqueSubject(Graph, IRI, Value, Resource[])` to a URI, or throws a GraphUtilException if that value is not a URI.
      Returns:
        The subject of the matched statement(s).
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getUniqueSubject(Graph, IRI, Value, Resource[])` or if its return value is not a URI.

    - #### getOptionalSubject

          @Deprecated
          public static Resource getOptionalSubject(Graph graph,
                                                                IRI pred,
                                                                Value obj,
                                                                Resource... contexts)
                                                         throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectResource()` instead.
      Gets the subject of the statement(s) with the specified predicate and object from the specified contexts in the supplied graph. If the combination of predicate, object and contexts matches one or more statements, all these statements should have the same subject. A `GraphUtilException` is thrown if this is not the case. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.
      Returns:
        The subject of the matched statement(s), or `null` if no matching statements were found.
      Throws:
        `GraphUtilException` - If the statements matched by the specified parameters have more than one unique subject.

    - #### getOptionalSubjectURI

          @Deprecated
          public static IRI getOptionalSubjectURI(Graph graph,
                                                              IRI pred,
                                                              Value obj,
                                                              Resource... contexts)
                                                       throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.subjectIRI()` instead.
      Utility method that casts the return value of `getOptionalSubject(Graph, IRI, Value, Resource[])` to a URI, or throws a GraphUtilException if that value is not a URI.
      Returns:
        The subject of the matched statement(s), or `null` if no matching statements were found.
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getOptionalSubject(Graph, IRI, Value, Resource[])` or if its return value is not a URI.

    - #### getObjectIterator

          @Deprecated
          public static Iterator<Value> getObjectIterator(Graph graph,
                                                                      Resource subj,
                                                                      IRI pred,
                                                                      Resource... contexts)

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objects()` instead.
      Gets the objects of the statements with the specified subject, predicate and (optionally) contexts from the supplied graph. Calling this method is equivalent to calling `graph.match(subj, pred, null, contexts)` and extracting the objects of the matching statements from the returned iterator. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.

    - #### getObjects

          @Deprecated
          public static Set<Value> getObjects(Graph graph,
                                                          Resource subj,
                                                          IRI pred,
                                                          Resource... contexts)

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objects()` instead.
      Gets the objects of the statements with the specified subject, predicate and (optionally) contexts from the supplied graph. Calling this method is equivalent to calling `graph.match(subj, pred, null, contexts)` and adding the objects of the matching statements to a set. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.

    - #### getUniqueObject

          @Deprecated
          public static Value getUniqueObject(Graph graph,
                                                          Resource subj,
                                                          IRI pred,
                                                          Resource... contexts)
                                                   throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectValue()` instead.
      Gets the object of the statement(s) with the specified subject and predicate from the specified contexts in the supplied graph. The combination of subject, predicate and contexts must match at least one statement. In case more than one statement matches -- for example statements from multiple contexts -- all these statements should have the same object. A `GraphUtilException` is thrown if these conditions are not met. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.
      Returns:
        The object of the matched statement(s).
      Throws:
        `GraphUtilException` - If the statements matched by the specified parameters do not have exactly one unique object.

    - #### setUniqueObject

          @Deprecated
          public static void setUniqueObject(Graph graph,
                                                         Resource subj,
                                                         IRI pred,
                                                         Value obj,
                                                         Resource... contexts)

      Deprecated. since 2.0. Use `Models.setProperty(Model, Resource, IRI, Value, Resource...)` instead.
      Adds the specified statement and makes sure that no other statements are present in the Graph with the same subject and predicate. When contexts are specified, the (subj, pred) pair will occur exactly once in each context, else the (subj, pred) pair will occur exactly once in the entire Graph.

    - #### getUniqueObjectResource

          @Deprecated
          public static Resource getUniqueObjectResource(Graph graph,
                                                                     Resource subj,
                                                                     IRI pred)
                                                              throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectResource()` instead.
      Utility method that casts the return value of `getUniqueObject(Graph, Resource, IRI, Resource[])` to a Resource, or throws a GraphUtilException if that value is not a Resource.
      Returns:
        The object of the matched statement(s).
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getUniqueObject(Graph, Resource, IRI, Resource[])` or if its return value is not a Resource.

    - #### getUniqueObjectURI

          @Deprecated
          public static IRI getUniqueObjectURI(Graph graph,
                                                           Resource subj,
                                                           IRI pred)
                                                    throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectIRI()` instead.
      Utility method that casts the return value of `getUniqueObject(Graph, Resource, IRI, Resource[])` to a URI, or throws a GraphUtilException if that value is not a URI.
      Returns:
        The object of the matched statement(s).
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getUniqueObject(Graph, Resource, IRI, Resource[])` or if its return value is not a URI.

    - #### getUniqueObjectLiteral

          @Deprecated
          public static Literal getUniqueObjectLiteral(Graph graph,
                                                                   Resource subj,
                                                                   IRI pred)
                                                            throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectLiteral()` instead.
      Utility method that casts the return value of `getUniqueObject(Graph, Resource, IRI, Resource[])` to a Literal, or throws a GraphUtilException if that value is not a Literal.
      Returns:
        The object of the matched statement(s).
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getUniqueObject(Graph, Resource, IRI, Resource[])` or if its return value is not a Literal.

    - #### getOptionalObject

          @Deprecated
          public static Value getOptionalObject(Graph graph,
                                                            Resource subj,
                                                            IRI pred,
                                                            Resource... contexts)
                                                     throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectValue()` instead.
      Gets the object of the statement(s) with the specified subject and predicate from the specified contexts in the supplied graph. If the combination of subject, predicate and contexts matches one or more statements, all these statements should have the same object. A `GraphUtilException` is thrown if this is not the case. See `Graph.match(Resource, IRI, Value, Resource[])` for a description of the parameter values.
      Returns:
        The object of the matched statement(s), or `null` if no matching statements were found.
      Throws:
        `GraphUtilException` - If the statements matched by the specified parameters have more than one unique object.

    - #### getOptionalObjectResource

          @Deprecated
          public static Resource getOptionalObjectResource(Graph graph,
                                                                       Resource subj,
                                                                       IRI pred)
                                                                throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectResource()` instead.
      Utility method that casts the return value of `getOptionalObject(Graph, Resource, IRI, Resource[])` to a Resource, or throws a GraphUtilException if that value is not a Resource.
      Returns:
        The object of the matched statement(s), or `null` if no matching statements were found.
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getOptionalObject(Graph, Resource, IRI, Resource[])` or if its return value is not a Resource.

    - #### getOptionalObjectURI

          @Deprecated
          public static IRI getOptionalObjectURI(Graph graph,
                                                             Resource subj,
                                                             IRI pred)
                                                      throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectIRI()` instead.
      Utility method that casts the return value of `getOptionalObject(Graph, Resource, IRI, Resource[])` to a URI, or throws a GraphUtilException if that value is not a URI.
      Returns:
        The object of the matched statement(s), or `null` if no matching statements were found.
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getOptionalObject(Graph, Resource, IRI, Resource[])` or if its return value is not a URI.

    - #### getOptionalObjectLiteral

          @Deprecated
          public static Literal getOptionalObjectLiteral(Graph graph,
                                                                     Resource subj,
                                                                     IRI pred)
                                                              throws GraphUtilException

      Deprecated. since 2.0. Use `Model.filter(Resource, IRI, Value, Resource...)` and `Model.objectLiteral()` instead.
      Utility method that casts the return value of `getOptionalObject(Graph, Resource, IRI, Resource[])` to a Literal, or throws a GraphUtilException if that value is not a Literal.
      Returns:
        The object of the matched statement(s), or `null` if no matching statements were found.
      Throws:
        `GraphUtilException` - If such an exception is thrown by `getOptionalObject(Graph, Resource, IRI, Resource[])` or if its return value is not a Literal.

    - #### remove

          @Deprecated
          public static void remove(Graph graph,
                                                Resource subj,
                                                IRI pred,
                                                Value obj,
                                                Resource... contexts)

      Deprecated. since 2.0. Use `Model.remove(Resource, IRI, Value, Resource...)` instead.
      Utility method that removes all statements matching the specified criteria from a graph.
      Parameters:
        `graph` - The graph to remove the statements from.
        `subj` - The subject of the statements to match, `null` to match statements with any subject.
        `pred` - The predicate of the statements to match, `null` to match statements with any predicate.
        `obj` - The object of the statements to match, `null` to match statements with any object.
        `contexts` - The contexts of the statements to match. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match.
      Throws:
        `IllegalArgumentException` - If a `null`-array is specified as the value for `contexts`. See `OpenRDFUtil.verifyContextNotNull(Resource[])` for more info.

Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.