addNewEdge
public Edge addNewEdge(Vertex firstEndpoint,
Vertex secondEndpoint,
Object annotation)
Add a new edge to the graph which joins the given (existing) vertices.
- addNewEdge in interface Graph
annotation
- optional annotation for this edge (or null
).
addNewVertex
public Vertex addNewVertex(Object annotation)
Create a new vertex and add it to the graph. The index of this
newly created vertex should be equal to the number of vertices
in the graph before that vertex was added.
- addNewVertex in interface Graph
annotation
- optional annotation for this vertex (or null
).
- the newly created vertex.
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
- areAdjacent in interface GraphView
change
public void change(Edge edge,
Object annotation)
Change or remove the annotation of the given edge.
- change in interface Graph
edge
- Edge whose annotation should be changedannotation
- new annotation for this element, or null
to request removal
change
public void change(Vertex vertex,
Object annotation)
Change or remove the annotation of the given vertex.
- change in interface Graph
vertex
- Vertex whose annotation should be changedannotation
- new annotation for this element, or null
to request removal
clear
public void clear()
Remove all vertices and all edges from this graph.
- clear in interface Graph
contains
public boolean contains(Edge edge)
Does the given edge belong to this graph?
- contains in interface GraphView
contains
public boolean contains(Vertex vertex)
Does the given vertex belong to this graph?
- contains in interface GraphView
copy
public void copy(GraphView original)
Make this graph a copy of the given view. Corresponding vertices will have
the same index in the copy as in the original. This graph will be cleared
prior to the copy operation.
- copy in interface Graph
edgeIterator
public Iterator edgeIterator()
Iterator over all edges of this graph.
- edgeIterator in interface GraphView
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
}
- edges in interface GraphView
finalizeRemoveEdge
protected void finalizeRemoveEdge(Edge edge)
finalizeRemoveVertex
protected void finalizeRemoveVertex(Vertex v)
getEdge
public Edge getEdge(Vertex first,
Vertex second)
Return an edge joining the given vertices, or null
when no such edge exists.
- getEdge in interface GraphView
- an edge having
first
as its first endpoint and
second
as its second endpoint.
getModCount
public int getModCount()
Returns the modification count of this graph. This count is incremented
every time the graph is changed and serves as a kind of version
number for this object.
getNumberOfEdges
public int getNumberOfEdges()
Returns the size, i.e. the number of edges, of the graph.
- getNumberOfEdges in interface GraphView
getNumberOfVertices
public int getNumberOfVertices()
Returns the order, i.e. the number of vertices, of the graph.
- getNumberOfVertices in interface GraphView
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
- getVertex in interface GraphView
remove
protected void remove(int index)
Remove vertex at given index position. The index is known to be
within range.
Extension classes should override this method rather than
remove(Vertex)
which calls this method.
This method is also used by the vertex iterator of this class.
remove
public void remove(Edge e)
Remove the given edge from the graph.
- remove in interface Graph
remove
public void remove(Vertex v)
Remove the given vertex from the graph. Also removes all
edges incident with this vertex. Removing a vertex makes its index negative
and may change the indices of other vertices in the same graph.
- remove in interface Graph
restore
public void restore(Edge e)
Restore a edge which was previously removed from the graph.
This method is intended for
use by the undo/redo framework and should be called with care. It is supposed
to undo a prior removal of that same edge. Clients are urged to instead
use
Graph.addNewEdge(Vertex,Vertex,Object)
whenever possible.
- restore in interface Graph
e
- Edge that should be restored. This must be a edge that was previously
removed from the same graph.
restore
public void restore(Vertex v)
Restore a vertex which was previously removed from the graph. The vertex
should end up at the same index position as it had before.
This method is intended for
use by the undo/redo framework and should be called with care. It is supposed
to undo a prior removal of that same vertex. Clients are urged to instead
use
Graph.addNewVertex(Object)
whenever possible.
- restore in interface Graph
v
- Vertex that should be restored. This must be a vertex that was previously
removed from the same graph.
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.
- vertexIterator in interface GraphView
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
}
- vertices in interface GraphView