Class DatasetGraphView

java.lang.Object
org.apache.commons.rdf.simple.DatasetGraphView
All Implemented Interfaces:
AutoCloseable, Graph, GraphLike<Triple>

public class DatasetGraphView extends Object implements Graph
A Graph view on a Dataset.

This view is backed by a Dataset, and can be constructed in two ways:

DatasetGraphView(Dataset)
Expose a union graph view of the Dataset, where all the Quads of the Dataset is represented as a Triple. Adding triples will add them to the default graph, while removing triples will remove from all graphs.
DatasetGraphView(Dataset, BlankNodeOrIRI)
Expose a particular graph of the Dataset, either named by an IRI, a BlankNode, or null for the default graph.

Changes in the Graph are reflected directly in the Dataset and vice versa. This class is thread-safe is the underlying Dataset is thread-safe.

  • Field Details

    • unionGraph

      private final boolean unionGraph
    • namedGraph

      private final BlankNodeOrIRI namedGraph
    • dataset

      private final Dataset dataset
  • Constructor Details

    • DatasetGraphView

      public DatasetGraphView(Dataset dataset)
    • DatasetGraphView

      public DatasetGraphView(Dataset dataset, BlankNodeOrIRI namedGraph)
  • Method Details

    • close

      public void close() throws Exception
      Description copied from interface: Graph
      Closes the graph, relinquishing any underlying resources.

      For example, this would close any open file and network streams and free database locks held by the Graph implementation.

      The behaviour of the other Graph methods are undefined after closing the graph.

      Implementations might not need Graph.close(), hence the default implementation does nothing.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Graph
      Throws:
      Exception
    • add

      public void add(Triple triple)
      Description copied from interface: Graph
      Adds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.
      Specified by:
      add in interface Graph
      Specified by:
      add in interface GraphLike<Triple>
      Parameters:
      triple - The triple to add
    • add

      public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Description copied from interface: Graph
      Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.
      Specified by:
      add in interface Graph
      Parameters:
      subject - The triple subject
      predicate - The triple predicate
      object - The triple object
    • contains

      public boolean contains(Triple triple)
      Description copied from interface: Graph
      Checks if graph contains triple.
      Specified by:
      contains in interface Graph
      Specified by:
      contains in interface GraphLike<Triple>
      Parameters:
      triple - The triple to check.
      Returns:
      True if the Graph contains the given Triple.
    • unionOrNamedGraph

      private Optional<BlankNodeOrIRI> unionOrNamedGraph()
    • contains

      public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Description copied from interface: Graph
      Checks if graph contains a pattern of triples.
      Specified by:
      contains in interface Graph
      Parameters:
      subject - The triple subject (null is a wildcard)
      predicate - The triple predicate (null is a wildcard)
      object - The triple object (null is a wildcard)
      Returns:
      True if the Graph contains any Triples that match the given pattern.
    • remove

      public void remove(Triple triple)
      Description copied from interface: Graph
      Removes a concrete triple from the graph.
      Specified by:
      remove in interface Graph
      Specified by:
      remove in interface GraphLike<Triple>
      Parameters:
      triple - triple to remove
    • remove

      public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Description copied from interface: Graph
      Removes a concrete pattern of triples from the graph.
      Specified by:
      remove in interface Graph
      Parameters:
      subject - The triple subject (null is a wildcard)
      predicate - The triple predicate (null is a wildcard)
      object - The triple object (null is a wildcard)
    • clear

      public void clear()
      Description copied from interface: Graph
      Clears the graph, removing all triples.
      Specified by:
      clear in interface Graph
      Specified by:
      clear in interface GraphLike<Triple>
    • size

      public long size()
      Description copied from interface: Graph
      Number of triples contained by the graph.

      The count of a set does not include duplicates, consistent with the Triple.equals(Object) equals method for each Triple.

      Specified by:
      size in interface Graph
      Specified by:
      size in interface GraphLike<Triple>
      Returns:
      The number of triples in the graph
    • stream

      public Stream<? extends Triple> stream()
      Description copied from interface: Graph
      Gets all triples contained by the graph.

      The iteration does not contain any duplicate triples, as determined by the Triple.equals(Object) method for each Triple.

      The behaviour of the Stream is not specified if Graph.add(Triple), Graph.remove(Triple) or Graph.clear() are called on the Graph before it terminates.

      Implementations may throw ConcurrentModificationException from Stream methods if they detect a conflict while the Stream is active.

      Specified by:
      stream in interface Graph
      Specified by:
      stream in interface GraphLike<Triple>
      Returns:
      A Stream over all of the triples in the graph
    • stream

      public Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Description copied from interface: Graph
      Gets all triples contained by the graph matched with the pattern.

      The iteration does not contain any duplicate triples, as determined by the Triple.equals(Object) method for each Triple.

      The behaviour of the Stream is not specified if Graph.add(Triple), Graph.remove(Triple) or Graph.clear() are called on the Graph before it terminates.

      Implementations may throw ConcurrentModificationException from Stream methods if they detect a conflict while the Stream is active.

      Specified by:
      stream in interface Graph
      Parameters:
      subject - The triple subject (null is a wildcard)
      predicate - The triple predicate (null is a wildcard)
      object - The triple object (null is a wildcard)
      Returns:
      A Stream over the matched triples.