org.grinvin

Interface GraphView

Known Subinterfaces:
Graph, GraphModel, MutableGraphModel
Known Implementing Classes:
DefaultGraph, DefaultGraphModel

public interface GraphView

Interface representing a read-only view of an abstract graph. An abstract graph is a collection of vertices (of type Vertex) connected by edges (of type Edge). The endpoints of edges that belong to a graph must be vertices that also belong to the graph.

This interface only provides read access to the graph. Use the interface Graph if you also need write access.

Method Summary

boolean
areAdjacent(Vertex v1, Vertex v2)
Check whether the given vertices are adjacent in this graph.
boolean
contains(Edge edge)
Does the given edge belong to this graph?
boolean
contains(Vertex vertex)
Does the given vertex belong to this graph?
Iterator
edgeIterator()
Iterator over all edges of this graph.
Iterable
edges()
Set of edges of this graph.
Edge
getEdge(Vertex first, Vertex second)
Return an edge joining the given vertices, or null when no such edge exists.
int
getNumberOfEdges()
Returns the size, i.e.
int
getNumberOfVertices()
Returns the order, i.e.
Vertex
getVertex(int index)
Returns the vertex with the given index in the graph.
Iterator
vertexIterator()
Iterator over all vertices of this graph.
Iterable
vertices()
Set of vertices of this graph.

Method Details

areAdjacent

public boolean areAdjacent(Vertex v1,
                           Vertex v2)
Check whether the given vertices are adjacent in this graph. Should return the same result as
    getEdge (first,second) != null || getEgde (second,first) != null
 

contains

public boolean contains(Edge edge)
Does the given edge belong to this graph?

contains

public boolean contains(Vertex vertex)
Does the given vertex belong to this graph?

edgeIterator

public Iterator edgeIterator()
Iterator over all edges of this graph.

edges

public Iterable edges()
Set of edges of this graph. This method returns an Iterable and not a java.util.Set so its main purpose is to be used in a 'for each' loop:
    for (Edge e: graph.edges()) {
        // do something with e
    }
 

getEdge

public Edge getEdge(Vertex first,
                    Vertex second)
Return an edge joining the given vertices, or null when no such edge exists.
Returns:
an edge having first as its first endpoint and second as its second endpoint.

getNumberOfEdges

public int getNumberOfEdges()
Returns the size, i.e. the number of edges, of the graph.

getNumberOfVertices

public int getNumberOfVertices()
Returns the order, i.e. the number of vertices, of the graph.

getVertex

public Vertex getVertex(int index)
Returns the vertex with the given index in the graph. Vertices in a graph are indexed in the range 0..n-1 where n is the number of vertices. Note that the index of a vertex is allowed to change whenever the graph is modified. Every graph should honour the following invariant whenever index is in the correct range:
    getVertex(index).getIndex() == index
 

vertexIterator

public Iterator vertexIterator()
Iterator over all vertices of this graph. If this iterator supports the remove operation, it should also remove all edges incident with the vertex that is removed.

vertices

public Iterable vertices()
Set of vertices of this graph. This method returns an Iterable and not a java.util.Set so its main purpose is to be used in a 'for each' loop:
    for (Vertex v: graph.vertices()) {
        // do something with v
    }