Interface Graph

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      void add​(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.
      void add​(Triple triple)
      Adds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.
      void clear()
      Clears the graph, removing all triples.
      default void close()
      Closes the graph, relinquishing any underlying resources.
      boolean contains​(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Checks if graph contains a pattern of triples.
      boolean contains​(Triple triple)
      Checks if graph contains triple.
      default java.util.stream.Stream<? extends Triple> getTriples()
      Deprecated.
      default java.util.stream.Stream<? extends Triple> getTriples​(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Deprecated.
      default java.lang.Iterable<Triple> iterate()
      Gets an Iterable for iterating over all triples in the graph.
      default java.lang.Iterable<Triple> iterate​(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Gets an Iterable for iterating over the triples in the graph that match the pattern.
      void remove​(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Removes a concrete pattern of triples from the graph.
      void remove​(Triple triple)
      Removes a concrete triple from the graph.
      long size()
      Number of triples contained by the graph.
      java.util.stream.Stream<? extends Triple> stream()
      Gets all triples contained by the graph.
      java.util.stream.Stream<? extends Triple> stream​(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
      Gets all triples contained by the graph matched with the pattern.
    • Method Detail

      • add

        void add​(Triple triple)
        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 GraphLike<Triple>
        Parameters:
        triple - The triple to add
      • add

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

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

        boolean contains​(BlankNodeOrIRI subject,
                         IRI predicate,
                         RDFTerm object)
        Checks if graph contains a pattern of triples.
        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.
      • close

        default void close()
                    throws java.lang.Exception
        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 close(), hence the default implementation does nothing.

        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • remove

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

        void remove​(BlankNodeOrIRI subject,
                    IRI predicate,
                    RDFTerm object)
        Removes a concrete pattern of triples from the 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

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

        long size()
        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 GraphLike<Triple>
        Returns:
        The number of triples in the graph
      • stream

        java.util.stream.Stream<? extends Triple> stream()
        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 add(Triple), remove(Triple) or 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 GraphLike<Triple>
        Returns:
        A Stream over all of the triples in the graph
        Since:
        0.3.0-incubating
      • stream

        java.util.stream.Stream<? extends Triple> stream​(BlankNodeOrIRI subject,
                                                         IRI predicate,
                                                         RDFTerm object)
        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 add(Triple), remove(Triple) or 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.

        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.
        Since:
        0.3.0-incubating
      • getTriples

        @Deprecated
        default java.util.stream.Stream<? extends Triple> getTriples()
        Deprecated.
        This method is deprecated, use the equivalent method stream() instead.
        Returns:
        A Stream over all triples.
      • getTriples

        @Deprecated
        default java.util.stream.Stream<? extends Triple> getTriples​(BlankNodeOrIRI subject,
                                                                     IRI predicate,
                                                                     RDFTerm object)
        Deprecated.
        This method is deprecated, use the equivalent method stream(BlankNodeOrIRI, IRI, RDFTerm) instead.
        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.
      • iterate

        default java.lang.Iterable<Triple> iterate()
                                            throws java.util.ConcurrentModificationException,
                                                   java.lang.IllegalStateException
        Gets an Iterable for iterating over all triples in the graph.

        This method is meant to be used with a Java for-each loop, e.g.:

         for (Triple t : graph.iterate()) {
             System.out.println(t);
         }
         
        The behaviour of the iterator is not specified if add(Triple), remove(Triple) or clear(), are called on the Graph before it terminates. It is undefined if the returned Iterator supports the Iterator.remove() method.

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

        The Iterable.iterator() must only be called once, that is the Iterable must only be iterated over once. A IllegalStateException may be thrown on attempt to reuse the Iterable.

        The default implementation of this method will call stream() to return its BaseStream.iterator().

        Specified by:
        iterate in interface GraphLike<Triple>
        Returns:
        A Iterable that returns Iterator over all of the triples in the graph
        Throws:
        java.lang.IllegalStateException - if the Iterable has been reused
        java.util.ConcurrentModificationException - if a concurrency conflict occurs while the Iterator is active.
      • iterate

        default java.lang.Iterable<Triple> iterate​(BlankNodeOrIRI subject,
                                                   IRI predicate,
                                                   RDFTerm object)
                                            throws java.util.ConcurrentModificationException,
                                                   java.lang.IllegalStateException
        Gets an Iterable for iterating over the triples in the graph that match the pattern.

        This method is meant to be used with a Java for-each loop, e.g.:

         IRI alice = factory.createIRI("http://example.com/alice");
         IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
         for (Triple t : graph.iterate(alice, knows, null)) {
             System.out.println(t.getObject());
         }
         

        The behaviour of the iterator is not specified if add(Triple), remove(Triple) or clear(), are called on the Graph before it terminates. It is undefined if the returned Iterator supports the Iterator.remove() method.

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

        The Iterable.iterator() must only be called once, that is the Iterable must only be iterated over once. A IllegalStateException may be thrown on attempt to reuse the Iterable.

        The default implementation of this method will call stream(BlankNodeOrIRI, IRI, RDFTerm) to return its BaseStream.iterator().

        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 Iterable that returns Iterator over the matching triples in the graph
        Throws:
        java.lang.IllegalStateException - if the Iterable has been reused
        java.util.ConcurrentModificationException - if a concurrency conflict occurs while the Iterator is active.