Class GraphImpl

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

final class GraphImpl extends Object implements Graph
A simple, memory-based implementation of Graph.

Triples in the graph are kept in a Set.

All Stream operations are performed using parallel and unordered directives.

  • Field Details

  • Constructor Details

  • Method Details

    • 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
    • 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
    • internallyMap

      private <T extends RDFTerm> RDFTerm internallyMap(T object)
    • internallyMap

      private Triple internallyMap(Triple triple)
    • 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>
    • 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.
    • 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.
    • stream

      public Stream<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<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.
    • getTriples

      private Stream<Triple> getTriples(Predicate<Triple> filter)
    • 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)
    • 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
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object