Class GraphBase

  • All Implemented Interfaces:
    Graph, GraphWithPerform
    Direct Known Subclasses:
    BaseInfGraph, CollectionGraph, CompositionBase, GraphMemBase

    public abstract class GraphBase
    extends java.lang.Object
    implements GraphWithPerform
    GraphBase is an implementation of Graph that provides some convenient base functionality for Graph implementations.

    Subtypes of GraphBase must provide performAdd(Triple), performDelete(Triple), graphBaseFind(TripleMatch,TripleAction), and graphBaseSize(). GraphBase provides default implementations of the other methods, including the other finds (on top of that one), a simple-minded prepare, and contains. GraphBase also handles the event-listening and registration interfaces.

    When a GraphBase is closed, future operations on it may throw an exception.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int TOSTRING_TRIPLE_BASE
      toString will not cut off up to this number of triples.
      static int TOSTRING_TRIPLE_LIMIT
      toString will not output more than this number of triples.
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphBase()
      Initialise this graph as one with reification style Minimal.
    • Field Detail

      • TOSTRING_TRIPLE_BASE

        public static final int TOSTRING_TRIPLE_BASE
        toString will not cut off up to this number of triples.
        See Also:
        Constant Field Values
      • TOSTRING_TRIPLE_LIMIT

        public static final int TOSTRING_TRIPLE_LIMIT
        toString will not output more than this number of triples.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GraphBase

        public GraphBase()
        Initialise this graph as one with reification style Minimal.
    • Method Detail

      • close

        public void close()
        Close this graph. Subgraphs may extend to discard resources.
        Specified by:
        close in interface Graph
      • isClosed

        public boolean isClosed()
        Description copied from interface: Graph
        Answer true iff .close() has been called on this Graph.
        Specified by:
        isClosed in interface Graph
      • dependsOn

        public boolean dependsOn​(Graph other)
        Default implementation answers true iff this graph is the same graph as the argument graph.
        Specified by:
        dependsOn in interface Graph
        Parameters:
        other - the graph this graph may depend on
        Returns:
        false if this does not depend on other
      • getEventManager

        public GraphEventManager getEventManager()
        Answer the event manager for this graph; allocate a new one if required. Subclasses may override if they have a more specialised event handler. The default is a SimpleEventManager.
        Specified by:
        getEventManager in interface Graph
      • notifyAdd

        public void notifyAdd​(Triple t)
        Tell the event manager that the triple t has been added to the graph.
      • notifyDelete

        public void notifyDelete​(Triple t)
        Tell the event manager that the triple t has been deleted from the graph.
      • getTransactionHandler

        public TransactionHandler getTransactionHandler()
        Answer a transaction handler bound to this graph. The default is SimpleTransactionHandler, which handles no transactions.
        Specified by:
        getTransactionHandler in interface Graph
      • getCapabilities

        public Capabilities getCapabilities()
        Answer the capabilities of this graph; the default is an AllCapabilities object (the same one each time, not that it matters - Capabilities should be immutable).
        Specified by:
        getCapabilities in interface Graph
      • getPrefixMapping

        public PrefixMapping getPrefixMapping()
        Answer the PrefixMapping object for this graph, the same one each time.
        Specified by:
        getPrefixMapping in interface Graph
      • add

        public void add​(Triple t)
        Add a triple, and notify the event manager. Subclasses should not need to override this - we might make it final. The triple is added using performAdd, and notification done by notifyAdd.
        Specified by:
        add in interface Graph
        Parameters:
        t - the triple to add to the graph
      • performAdd

        public void performAdd​(Triple t)
        Add a triple to the triple store. The default implementation throws an AddDeniedException; subclasses must override if they want to be able to add triples.
        Specified by:
        performAdd in interface GraphWithPerform
      • delete

        public final void delete​(Triple t)
        Delete a triple, and notify the event manager. Subclasses should not need to override this - we might make it final. The triple is added using performDelete, and notification done by notifyDelete.
        Specified by:
        delete in interface Graph
        Parameters:
        t - the triple to delete to the graph
      • performDelete

        public void performDelete​(Triple t)
        Remove a triple from the triple store. The default implementation throws a DeleteDeniedException; subclasses must override if they want to be able to remove triples.
        Specified by:
        performDelete in interface GraphWithPerform
      • clear

        public void clear()
        Remove all the statements from this graph.
        Specified by:
        clear in interface Graph
      • remove

        public void remove​(Node s,
                           Node p,
                           Node o)
        Remove all triples that match by find(s, p, o)
        Specified by:
        remove in interface Graph
      • find

        public final ExtendedIterator<Triple> find​(Triple m)
        Description copied from interface: Graph
        Returns an iterator over all the Triples that match the triple pattern.
        Specified by:
        find in interface Graph
        Parameters:
        m - a Triple encoding the pattern to look for
        Returns:
        an iterator of all triples in this graph that match m
      • find

        public final ExtendedIterator<Triple> find​(Node s,
                                                   Node p,
                                                   Node o)
        Description copied from interface: Graph
        Returns an iterator over Triples matching a pattern.
        Specified by:
        find in interface Graph
        Returns:
        an iterator of triples in this graph matching the pattern.
      • contains

        public final boolean contains​(Triple t)
        Answer true iff t is in the graph as revealed by find(t) being non-empty. t may contain ANY wildcards. Sub-classes may over-ride graphBaseContains for efficiency.
        Specified by:
        contains in interface Graph
      • contains

        public final boolean contains​(Node s,
                                      Node p,
                                      Node o)
        Answer true if this graph contains (s, p, o); this canonical implementation cannot be over-ridden.
        Specified by:
        contains in interface Graph
      • size

        public final int size()
        Answer the size of this graph (ie the number of exposed triples). Defined as the size of the triple store plus the size of the reification store. Subclasses must override graphBaseSize() to reimplement (and reifierSize if they have some special reason for redefined that).
        Specified by:
        size in interface Graph
      • isEmpty

        public boolean isEmpty()
        Answer true iff this graph contains no triples (hidden reification quads do not count). The default implementation is size() == 0, which is fine if size is reasonable efficient. Subclasses may override if necessary. This method may become final and defined in terms of other methods.
        Specified by:
        isEmpty in interface Graph
      • isIsomorphicWith

        public boolean isIsomorphicWith​(Graph g)
        Answer true iff this graph is isomorphic to g according to the algorithm (indeed, method) in GraphMatcher.
        Specified by:
        isIsomorphicWith in interface Graph
        Parameters:
        g - Compare against this.
        Returns:
        boolean True if the two graphs are isomorphic.
      • toString

        public java.lang.String toString()
        Answer a human-consumable representation of this graph. Not advised for big graphs, as it generates a big string: intended for debugging purposes.
        Overrides:
        toString in class java.lang.Object
      • toString

        public static java.lang.String toString​(java.lang.String prefix,
                                                Graph that)
        Answer a human-consumable representation of that. The string prefix will appear near the beginning of the string. Nodes may be prefix-compressed using that's prefix-mapping. This default implementation will display all the triples exposed by the graph (ie including reification triples if it is Standard).