Class DefaultGraphImpl<V>

    • Constructor Detail

      • DefaultGraphImpl

        public DefaultGraphImpl​(EdgeFactory<V> edgeFactory)
        Instantiates a new Adjacency matrix.
        Parameters:
        edgeFactory - the edge factory
    • Method Detail

      • addEdge

        public Edge<V> addEdge​(V fromVertex,
                               V toVertex)
        Description copied from interface: Graph
        Adds an edge to the graph
        Specified by:
        addEdge in interface Graph<V>
        Parameters:
        fromVertex - The first (from) vertex
        toVertex - The second (to) vertex
        Returns:
        The edge that was created
      • addEdge

        public Edge<V> addEdge​(V fromVertex,
                               V toVertex,
                               double weight)
        Description copied from interface: Graph
        Adds an edge to the graph
        Specified by:
        addEdge in interface Graph<V>
        Parameters:
        fromVertex - The first (from) vertex
        toVertex - The second (to) vertex
        weight - The weight of the edge
        Returns:
        The edge that was created
      • addEdge

        public void addEdge​(Edge<V> edge)
        Description copied from interface: Graph
        Adds an edge to the graph.
        Specified by:
        addEdge in interface Graph<V>
        Parameters:
        edge - the edge
      • addVertex

        public boolean addVertex​(V vertex)
        Description copied from interface: Graph
        Adds a vertex to the graph
        Specified by:
        addVertex in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        True if the vertex was added, False if not
      • addVertices

        public void addVertices​(Collection<V> vertices)
        Description copied from interface: Graph
        Adds all vertices in a collection to the graph
        Specified by:
        addVertices in interface Graph<V>
        Parameters:
        vertices - The vertices to add
      • containsEdge

        public boolean containsEdge​(V fromVertex,
                                    V toVertex)
        Description copied from interface: Graph
        Checks if an edge in the graph
        Specified by:
        containsEdge in interface Graph<V>
        Parameters:
        fromVertex - The first (from) vertex
        toVertex - The second (to) vertex
        Returns:
        True if the edge is in the graph, false if not
      • containsVertex

        public boolean containsVertex​(V vertex)
        Description copied from interface: Graph
        Checks if a vertex in the graph
        Specified by:
        containsVertex in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        True if the vertex is in the graph, false if not
      • degree

        public int degree​(V vertex)
        Description copied from interface: Graph
        The number of neighbors
        Specified by:
        degree in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        The degree
      • edges

        public Set<? extends Edge<V>> edges()
        Description copied from interface: Graph
        Edges set.
        Specified by:
        edges in interface Graph<V>
        Returns:
        The set of edges in the graph
      • getEdge

        public Edge<V> getEdge​(V v1,
                               V v2)
        Description copied from interface: Graph
        Gets the edge if one, between the two given vertices
        Specified by:
        getEdge in interface Graph<V>
        Parameters:
        v1 - vertex 1
        v2 - vertex 2
        Returns:
        The edge if one, null otherwise
      • getEdgeFactory

        public EdgeFactory<V> getEdgeFactory()
        Description copied from interface: Graph
        Gets the edge factory used in this grapy
        Specified by:
        getEdgeFactory in interface Graph<V>
        Returns:
        The edge factory
      • getInEdges

        public Set<? extends Edge<V>> getInEdges​(V vertex)
        Description copied from interface: Graph
        Gets the edges coming in to the given vertex (i.e. in-links)
        Specified by:
        getInEdges in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        The set of incoming edges
      • getOutEdges

        public Set<? extends Edge<V>> getOutEdges​(V vertex)
        Description copied from interface: Graph
        Gets the edges coming out out of the given vertex (i.e. out-links)
        Specified by:
        getOutEdges in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        The set of outgoing edges
      • getPredecessors

        public Set<V> getPredecessors​(V vertex)
        Description copied from interface: Graph
        Gets the neighbors associated with the incoming edges for the given vertex.
        Specified by:
        getPredecessors in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        The set of vertices which contain an outgoing edge to the given vertex.
      • getSuccessors

        public Set<V> getSuccessors​(V vertex)
        Description copied from interface: Graph
        Gets the neighbors associated with the outgoing edges for the given vertex.
        Specified by:
        getSuccessors in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        The set of vertices which contain an incoming edge from the given vertex.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • inDegree

        public int inDegree​(V vertex)
        Description copied from interface: Graph
        The number of predecessors
        Specified by:
        inDegree in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        The in degree
      • isDirected

        public boolean isDirected()
        Description copied from interface: Graph
        Is directed.
        Specified by:
        isDirected in interface Graph<V>
        Returns:
        True if the graph is directed, false if it is undirected
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Graph
        Determines if the graph is empty (no vertices no edges)
        Specified by:
        isEmpty in interface Graph<V>
        Returns:
        True if the graph is empty
      • numberOfEdges

        public int numberOfEdges()
        Description copied from interface: Graph
        Number of edges.
        Specified by:
        numberOfEdges in interface Graph<V>
        Returns:
        Number of edges in the graph
      • numberOfVertices

        public int numberOfVertices()
        Description copied from interface: Graph
        Number of vertices.
        Specified by:
        numberOfVertices in interface Graph<V>
        Returns:
        Number of vertices in the graph
      • outDegree

        public int outDegree​(V vertex)
        Description copied from interface: Graph
        The number of successors
        Specified by:
        outDegree in interface Graph<V>
        Parameters:
        vertex - The vertex
        Returns:
        The out degree
      • removeEdge

        public Edge<V> removeEdge​(V fromVertex,
                                  V toVertex)
        Description copied from interface: Graph
        Removes an edge from the graph
        Specified by:
        removeEdge in interface Graph<V>
        Parameters:
        fromVertex - The first (from) vertex
        toVertex - The second (to) vertex
        Returns:
        The edge that was removed or null if there was no edge
      • removeEdge

        public boolean removeEdge​(Edge<V> edge)
        Description copied from interface: Graph
        Removes an edge from the graph
        Specified by:
        removeEdge in interface Graph<V>
        Parameters:
        edge - The edge to remove
        Returns:
        True if the edge was removed, false if not
      • removeVertex

        public boolean removeVertex​(V vertex)
        Description copied from interface: Graph
        Removes a vertex from the graph
        Specified by:
        removeVertex in interface Graph<V>
        Parameters:
        vertex - The vertex to remove
        Returns:
        True if the vertex was removed, false if not
      • vertices

        public Set<V> vertices()
        Description copied from interface: Graph
        Vertices set.
        Specified by:
        vertices in interface Graph<V>
        Returns:
        The set of vertices in the graph