|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Graph
A Graph in an interface for a table of vertices and a table of edges, along with a set of methods to manage these tables as a graph.
Graph manage vertices and edges. Contrary to other graph
packages, InfoVis does not implement a Vertex and Edge class. A
vertex is simply an index in the table of vertices and an edge is
an index in the table of edges. Apart from that rather unusual
lack of object-orientedness, the provided interface is very
similar to other graph packages. Simply, each time you think
of the pseudo type Vertex
or Edge
,
replace it by int
. For example:
int vertex1 = graph.addVertex(); int vertex2 = graph.addVertex(); int edge1 = graph.addEdge(vertex1, vertex2);
Any number of attrbutes can be added to vertices and edges, simply by adding columns to the vertex table and edge table:
// Create a name for vertices StringColumn name = new StringColumn("name"); graph.getVertexTable().addColumn(name); // Create a length for edges IntColumn length = new IntColumn("length"); graph.getEdgeTable().addColumn(length); // Create 10 vertices linked together // and named vertex0, vertex1, ... int prev = graph.addVertex(); name.setExtend(v, "vertex0"); for (int i = 1; i < 10; i++) { int v = graph.addVertex(); name.setExtend(v, "vertex"+i); // Edge with previous vertex int e = graph.addEdge(prev, v); // Associate it a length of i length.setExtend(e, i); prev = v; }
Field Summary | |
---|---|
static String |
GRAPH_TYPE
Metadata key for the graph type. |
static String |
GRAPH_TYPE_DIRECTED
Metadata value for a directed graph. |
static String |
GRAPH_TYPE_UNDIRECTED
Metadata value for an undirected graph. |
static int |
NIL
NIL value for a vertex or edge. |
Fields inherited from interface infovis.metadata.Constants |
---|
CONTRIBUTOR, COVERAGE, CREATOR, DATE, DESCRITION, FORMAT, IDENTIFIER, LANGUAGE, PUBLISHER, RELATION, RIGHTS, SOURCE, SUBJECT, TITLE, TYPE |
Method Summary | |
---|---|
int |
addEdge(int v1,
int v2)
Adds a new edge between two vertices. |
void |
addGraphChangedListener(GraphChangedListener l)
Attaches a GraphChangedListener to the graph. |
int |
addVertex()
Adds a new "in" vertex to the graph. |
void |
clear()
Clears the Graph. |
RowIterator |
edgeIterator()
Returns an iterator over the edges of the graph. |
RowIterator |
edgeIterator(int vertex)
Returns an iterator over all the edges (incoming and outgoing) of a specified vertex. |
int |
findEdge(int v1,
int v2)
Returns an edge between two specified vertices. |
int |
getDegree(int vertex)
Returns the degree of the vertex, which is inDegree + outDegree. |
int |
getEdge(int v1,
int v2)
Returns an edge between two specified vertices. |
int |
getEdgesCount()
Returns the number of edges in the graph. |
DynamicTable |
getEdgeTable()
Returns the edgeTable. |
int |
getFirstVertex(int edge)
Returns the first vertex of the specified edge. |
int |
getInDegree(int vertex)
Returns the in degree of the vertex, which is simply the number of incoming edges at the vertex. |
int |
getInEdgeAt(int vertex,
int index)
Returns the incoming edge of a specified vertrex at a specified index. |
String |
getName()
Returns the Graph name. |
int |
getOtherVertex(int edge,
int vertex)
Given a specified edge and a vertex on one side of this edge, returns the vertex on the other side. |
int |
getOutDegree(int vertex)
Returns the out degree of the vertex, which is simply the number of outgoing edges of the vertex. |
int |
getOutEdgeAt(int vertex,
int index)
Returns the outgoing edge of a specified vertex at a specified index. |
int |
getSecondVertex(int edge)
Returns the second vertex of an edge. |
DynamicTable |
getVertexTable()
Returns the vertex Table. |
int |
getVerticesCount()
Returns the number of vertices in the graph. |
RowIterator |
inEdgeIterator(int vertex)
Returns an iterator over the incoming edges of specified vertex. |
boolean |
isDirected()
Returns true if the graph is directed. |
RowIterator |
outEdgeIterator(int vertex)
Returns an iterator over the outgoing edges of a specified vertex. |
void |
removeEdge(int edge)
Removes the specified edge. |
void |
removeGraphChangedListener(GraphChangedListener l)
Removes a GraphChangedListener from the graph. |
void |
removeVertex(int vertex)
Removes the specified vertex from the graph. |
void |
setDirected(boolean directed)
Sets the graph to directed or undirected. |
void |
setName(String name)
Sets the Graph name. |
RowIterator |
vertexIterator()
Returns an iterator over the vertices of the graph. |
Methods inherited from interface infovis.Metadata |
---|
getClientProperty, getMetadata |
Field Detail |
---|
static final String GRAPH_TYPE
static final String GRAPH_TYPE_DIRECTED
static final String GRAPH_TYPE_UNDIRECTED
static final int NIL
Method Detail |
---|
String getName()
void setName(String name)
name
- The Graph name to setvoid clear()
After this method, the graph tables are almost in the same state as if it had been created afresh except it contains the same columns as before but they are all cleared.
boolean isDirected()
void setDirected(boolean directed)
directed
- boolean specifying whether the graph is directed or not.int getVerticesCount()
int addVertex()
void removeVertex(int vertex)
vertex
- the vertex to removeint getEdgesCount()
int addEdge(int v1, int v2)
v1
- the first vertex.v2
- the second vertex.
void removeEdge(int edge)
edge
- the edge to removeint getFirstVertex(int edge)
edge
- the edge.
int getOtherVertex(int edge, int vertex)
edge
- the edgevertex
- the vertex
int getSecondVertex(int edge)
edge
- the edge.
int getOutEdgeAt(int vertex, int index)
vertex
- the in vertex of the requested edgeindex
- the index of the edge in the edge list of the vertex
int getInEdgeAt(int vertex, int index)
vertex
- the out vertex of the requested edgeindex
- the index of the edge in the edge list of the vertex
int getEdge(int v1, int v2)
v1
- the first vertex.v2
- the second vertex.
int findEdge(int v1, int v2)
v1
- the first vertex.v2
- the second vertex.
int getOutDegree(int vertex)
vertex
- the vertex.
RowIterator outEdgeIterator(int vertex)
vertex
- the vertex.
int getInDegree(int vertex)
vertex
- the vertex.
RowIterator inEdgeIterator(int vertex)
vertex
- the vertex
int getDegree(int vertex)
vertex
- the vertex.
RowIterator edgeIterator(int vertex)
vertex
- the vertex.
RowIterator vertexIterator()
RowIterator edgeIterator()
DynamicTable getEdgeTable()
DynamicTable getVertexTable()
void addGraphChangedListener(GraphChangedListener l)
l
- the GraphChangedListener to notify when the graph structure changes.void removeGraphChangedListener(GraphChangedListener l)
l
- the GraphChangedListener to remove
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |