Interface Graph<ID>

  • Type Parameters:
    ID - type of all identifiers in graph
    All Known Subinterfaces:
    EventGraph<ID>
    All Known Implementing Classes:
    AbstractGraph, DirectedGraph, UndirectedGraph

    public interface Graph<ID>
    A graph is composed of vertices and edges. A vertex is able to connect to other vertices through edges. Edges connect two vertices. A graph can be directed or undirected.

    Vertices have an 'id' which uniquely identifies the vertex within the graph. Edges have a 'to' and 'from' property which are the ids of the vertex endpoints. Edges are optionally identified.

    At all times the graph is valid event when removing connected vertices.

    Undirected graphs ignore 'from'/'to' order in edges.

    Once a vertex or edge is removed it can no longer modify the graph or be modified.

    • Method Detail

      • getVertices

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

        Collection<Graph.Edge<ID>> getEdges()
        Returns an ordered collection of all edges in this graph.
        Returns:
        ordered collection of all edges
      • getEdgeIds

        Map<ID,​Graph.Edge<ID>> getEdgeIds()
        Returns a map of edge ids to edges.
        Returns:
        map of edge ids to edges
      • findVertex

        Optional<Graph.Vertex<ID>> findVertex​(ID id)
        Finds vertex with given id. If vertex is not in this graph the optional is empty.
        Parameters:
        id - of vertex
        Returns:
        optional of vertex
        Throws:
        NullPointerException - if id is null
      • vertex

        Graph.Vertex<ID> vertex​(ID id)
        Ensure a vertex exists with id and returns the vertex. If the vertex does not exist it is created.
        Parameters:
        id - of vertex
        Returns:
        created or existing vertex
        Throws:
        NullPointerException - if id is null
      • removeVertex

        void removeVertex​(ID id)
        Removes vertex with given id. If edges connect to the vertex they are removed first.
        Parameters:
        id - of vertex
        Throws:
        NullPointerException - if id is null
      • findEdge

        Optional<Graph.Edge<ID>> findEdge​(ID from,
                                          ID to)
        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.
        Parameters:
        from - of edge
        to - of edge
        Returns:
        optional of edge
        Throws:
        NullPointerException - if from or to is null
      • findEdge

        Optional<Graph.Edge<ID>> findEdge​(ID id)
        finds edge with given id. If edge is not in this graph the optional is empty.
        Parameters:
        id - of edge
        Returns:
        optional of edge
        Throws:
        NullPointerException - if id is null
      • edge

        Graph.Edge<ID> edge​(ID from,
                            ID to)
        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.

        Parameters:
        from - of edge
        to - of edge
        Returns:
        created or existing edge
      • getId

        Optional<ID> getId()
        Returns the id of this graph. If the id is not set and empty optional is returned.
        Returns:
        optional of id
      • setId

        void setId​(ID id)
        Sets the id of this graph.
        Parameters:
        id - of graph
        Throws:
        NullPointerException - if id is null
      • id

        Graph<ID> id​(ID id)
        Sets the id of this graph
        Parameters:
        id - of graph
        Returns:
        this graph
        Throws:
        NullPointerException - if id is null
      • isDirected

        boolean isDirected()
        Returns true if this graph is directed.
        Returns:
        if this graph is directed
      • getProperties

        Map<String,​Object> getProperties()
        Returns an unmodifiable map of properties for this graph.
        Returns:
        an unmodifiable map of properties for this graph
      • setProperty

        void setProperty​(String name,
                         Object value)
        Sets property on this graph
        Parameters:
        name - of property
        value - of property
        Throws:
        NullPointerException - if name or value is null
      • property

        Graph<ID> property​(String name,
                           Object value)
        Sets property on this graph returning this graph
        Parameters:
        name - of property
        value - of property
        Returns:
        this graph
        Throws:
        NullPointerException - if name or value is null
      • removeProperty

        Graph<ID> removeProperty​(String name)
        Removes property on this graph returning this graph
        Parameters:
        name - of property
        Returns:
        this graph
        Throws:
        NullPointerException - if name is null
      • getEdgeProperties

        Map<String,​Object> getEdgeProperties()
        Returns an unmodifiable map of edge properties.
        Returns:
        an unmodifiable map of edge properties
      • setEdgeProperty

        void setEdgeProperty​(String name,
                             Object value)
        Sets edge property.
        Parameters:
        name - of property
        value - of property
        Throws:
        NullPointerException - if name or value is null
      • edgeProperty

        Graph<ID> edgeProperty​(String name,
                               Object value)
        Sets edge property returning this graph
        Parameters:
        name - of edge property
        value - of edge property
        Returns:
        this graph
        Throws:
        NullPointerException - if name or value is null
      • removeEdgeProperty

        Graph<ID> removeEdgeProperty​(String name)
        Removes edge property returning this graph
        Parameters:
        name - of property
        Returns:
        this graph
        Throws:
        NullPointerException - if name is null
      • getVertexProperties

        Map<String,​Object> getVertexProperties()
        Retruns an unmodifiable map of vertex properties.
        Returns:
        an unmodifiable map of vertex properties
      • getVertexProperty

        Optional<Object> getVertexProperty​(String name)
        Returns Optional of a vertex property. If the property does not exist the returned Optional is empty.
        Parameters:
        name - of property
        Returns:
        optional of property
        Throws:
        NullPointerException - if name is null
      • setVertexProperty

        void setVertexProperty​(String name,
                               Object value)
        Sets vertex property.
        Parameters:
        name - of property
        value - of property
        Throws:
        NullPointerException - if name or value is null
      • vertexProperty

        Graph<ID> vertexProperty​(String name,
                                 Object value)
        Sets vertex property returning this graph
        Parameters:
        name - of property
        value - of property
        Returns:
        created or existing edge
        Throws:
        NullPointerException - if name or value is null
      • removeVertexProperty

        Graph<ID> removeVertexProperty​(String name)
        Removes vertex property returning this graph
        Parameters:
        name - of property
        Returns:
        this graph
        Throws:
        NullPointerException - if name is null