Class AbstractGraph<ID>

  • Type Parameters:
    ID - type of all identifiers in graph
    All Implemented Interfaces:
    Graph<ID>
    Direct Known Subclasses:
    DirectedGraph, UndirectedGraph

    public abstract class AbstractGraph<ID>
    extends Object
    implements Graph<ID>
    This class provides a partial implementation of the Graph interface.

    Vertices and edges are stored in insertion order.

    • Constructor Detail

      • AbstractGraph

        protected AbstractGraph()
      • AbstractGraph

        protected AbstractGraph​(ID id)
    • Method Detail

      • getVertices

        public Map<ID,​Graph.Vertex<ID>> getVertices()
        Description copied from interface: Graph
        Returns an ordered map of all vertices in this graph. The key is the vertex id. Ordering is determined by implementing class.
        Specified by:
        getVertices in interface Graph<ID>
        Returns:
        ordered map of all vertices in this graph
      • getEdges

        public Collection<Graph.Edge<ID>> getEdges()
        Description copied from interface: Graph
        Returns an ordered collection of all edges in this graph.
        Specified by:
        getEdges in interface Graph<ID>
        Returns:
        ordered collection of all edges
      • getEdgeIds

        public Map<ID,​Graph.Edge<ID>> getEdgeIds()
        Description copied from interface: Graph
        Returns a map of edge ids to edges.
        Specified by:
        getEdgeIds in interface Graph<ID>
        Returns:
        map of edge ids to edges
      • findVertex

        public Optional<Graph.Vertex<ID>> findVertex​(ID id)
        Description copied from interface: Graph
        Finds vertex with given id. If vertex is not in this graph the optional is empty.
        Specified by:
        findVertex in interface Graph<ID>
        Parameters:
        id - of vertex
        Returns:
        optional of vertex
      • vertex

        public Graph.Vertex<ID> vertex​(ID id)
        Description copied from interface: Graph
        Ensure a vertex exists with id and returns the vertex. If the vertex does not exist it is created.
        Specified by:
        vertex in interface Graph<ID>
        Parameters:
        id - of vertex
        Returns:
        created or existing vertex
      • removeVertex

        public void removeVertex​(ID id)
        Description copied from interface: Graph
        Removes vertex with given id. If edges connect to the vertex they are removed first.
        Specified by:
        removeVertex in interface Graph<ID>
        Parameters:
        id - of vertex
      • findEdge

        public Optional<Graph.Edge<ID>> findEdge​(ID from,
                                                 ID to)
        Description copied from interface: Graph
        Finds edge connecting 'from' and 'to' vertex. If edge is not in this graph the optional is empty. The order of 'from' and 'to' does not matter in undirected implementations. However, if the graph is directed 'from' and 'to' must match 'from' and 'to' of the edge exactly.
        Specified by:
        findEdge in interface Graph<ID>
        Parameters:
        from - of edge
        to - of edge
        Returns:
        optional of edge
      • findEdge

        public Optional<Graph.Edge<ID>> findEdge​(ID id)
        Description copied from interface: Graph
        finds edge with given id. If edge is not in this graph the optional is empty.
        Specified by:
        findEdge in interface Graph<ID>
        Parameters:
        id - of edge
        Returns:
        optional of edge
      • edge

        public Graph.Edge<ID> edge​(ID from,
                                   ID to)
        Description copied from interface: Graph
        Ensures an edge exists between 'from' and 'to' vertices. If an edge does not exist it is created. If any of the vertices do not exist they are created.

        If this graph is undirected and contains an edge connecting 'to' and 'from' the edge will not be created. Undirected graphs ignore 'from'/'to' order in edges.

        Specified by:
        edge in interface Graph<ID>
        Parameters:
        from - of edge
        to - of edge
        Returns:
        created or existing edge
      • newEdgeKey

        protected abstract EdgeKey<ID> newEdgeKey​(ID from,
                                                  ID to)
      • removeEdge

        public void removeEdge​(ID from,
                               ID to)
        Description copied from interface: Graph
        Removes edge with given from and to.
        Specified by:
        removeEdge in interface Graph<ID>
        Parameters:
        from - of edge
        to - of edge
      • removeEdge

        public void removeEdge​(ID id)
        Description copied from interface: Graph
        Removes edge with given id
        Specified by:
        removeEdge in interface Graph<ID>
        Parameters:
        id - of edge
      • getId

        public Optional<ID> getId()
        Description copied from interface: Graph
        Returns the id of this graph. If the id is not set and empty optional is returned.
        Specified by:
        getId in interface Graph<ID>
        Returns:
        optional of id
      • setId

        public void setId​(ID id)
        Description copied from interface: Graph
        Sets the id of this graph.
        Specified by:
        setId in interface Graph<ID>
        Parameters:
        id - of graph
      • id

        public Graph<ID> id​(ID id)
        Description copied from interface: Graph
        Sets the id of this graph
        Specified by:
        id in interface Graph<ID>
        Parameters:
        id - of graph
        Returns:
        this graph
      • getProperties

        public Map<String,​Object> getProperties()
        Description copied from interface: Graph
        Returns an unmodifiable map of properties for this graph.
        Specified by:
        getProperties in interface Graph<ID>
        Returns:
        an unmodifiable map of properties for this graph
      • getProperty

        public Optional<Object> getProperty​(String name)
        Description copied from interface: Graph
        Returns Optional of a property. If the property does not exist the returned Optional is empty.
        Specified by:
        getProperty in interface Graph<ID>
        Parameters:
        name - of property
        Returns:
        optional of named proeprty
      • setProperty

        public void setProperty​(String name,
                                Object value)
        Description copied from interface: Graph
        Sets property on this graph
        Specified by:
        setProperty in interface Graph<ID>
        Parameters:
        name - of property
        value - of property
      • property

        public Graph<ID> property​(String name,
                                  Object value)
        Description copied from interface: Graph
        Sets property on this graph returning this graph
        Specified by:
        property in interface Graph<ID>
        Parameters:
        name - of property
        value - of property
        Returns:
        this graph
      • removeProperty

        public Graph<ID> removeProperty​(String name)
        Description copied from interface: Graph
        Removes property on this graph returning this graph
        Specified by:
        removeProperty in interface Graph<ID>
        Parameters:
        name - of property
        Returns:
        this graph
      • getEdgeProperties

        public Map<String,​Object> getEdgeProperties()
        Description copied from interface: Graph
        Returns an unmodifiable map of edge properties.
        Specified by:
        getEdgeProperties in interface Graph<ID>
        Returns:
        an unmodifiable map of edge properties
      • getEdgeProperty

        public Optional<Object> getEdgeProperty​(String name)
        Description copied from interface: Graph
        Returns Optional of an edge property. If the property does not exist the returned Optional is empty.
        Specified by:
        getEdgeProperty in interface Graph<ID>
        Parameters:
        name - of property
        Returns:
        optional of property
      • setEdgeProperty

        public void setEdgeProperty​(String name,
                                    Object value)
        Description copied from interface: Graph
        Sets edge property.
        Specified by:
        setEdgeProperty in interface Graph<ID>
        Parameters:
        name - of property
        value - of property
      • edgeProperty

        public Graph<ID> edgeProperty​(String name,
                                      Object value)
        Description copied from interface: Graph
        Sets edge property returning this graph
        Specified by:
        edgeProperty in interface Graph<ID>
        Parameters:
        name - of edge property
        value - of edge property
        Returns:
        this graph
      • removeEdgeProperty

        public Graph<ID> removeEdgeProperty​(String name)
        Description copied from interface: Graph
        Removes edge property returning this graph
        Specified by:
        removeEdgeProperty in interface Graph<ID>
        Parameters:
        name - of property
        Returns:
        this graph
      • getVertexProperties

        public Map<String,​Object> getVertexProperties()
        Description copied from interface: Graph
        Retruns an unmodifiable map of vertex properties.
        Specified by:
        getVertexProperties in interface Graph<ID>
        Returns:
        an unmodifiable map of vertex properties
      • getVertexProperty

        public Optional<Object> getVertexProperty​(String name)
        Description copied from interface: Graph
        Returns Optional of a vertex property. If the property does not exist the returned Optional is empty.
        Specified by:
        getVertexProperty in interface Graph<ID>
        Parameters:
        name - of property
        Returns:
        optional of property
      • setVertexProperty

        public void setVertexProperty​(String name,
                                      Object value)
        Description copied from interface: Graph
        Sets vertex property.
        Specified by:
        setVertexProperty in interface Graph<ID>
        Parameters:
        name - of property
        value - of property
      • vertexProperty

        public Graph<ID> vertexProperty​(String name,
                                        Object value)
        Description copied from interface: Graph
        Sets vertex property returning this graph
        Specified by:
        vertexProperty in interface Graph<ID>
        Parameters:
        name - of property
        value - of property
        Returns:
        created or existing edge
      • removeVertexProperty

        public Graph<ID> removeVertexProperty​(String name)
        Description copied from interface: Graph
        Removes vertex property returning this graph
        Specified by:
        removeVertexProperty in interface Graph<ID>
        Parameters:
        name - of property
        Returns:
        this graph
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object