public interface UndirectedGraph<V,E>
getVertices()
and getEdges()
.Modifier and Type | Method and Description |
---|---|
int |
addEdge(int v1,
int v2,
E obj)
Create an edge between the two specified vertices and notify the
UndirectedGraphListener s. |
void |
addListener(UndirectedGraphListener l)
Add a
UndirectedGraphListener to get notified when the graph changes. |
int |
addVertex()
Create a new vertex and notify the
UndirectedGraphListener s. |
java.util.List<gnu.trove.list.array.TIntArrayList> |
findAllPaths(int from,
java.util.function.Function<V,java.lang.Boolean> pathComplete,
java.util.function.Function<E,java.lang.Boolean> pathCancelled)
Find all paths from the specified vertex.
|
int |
getEdgeCount()
Return the number of edges.
|
E |
getEdgeObject(int e)
Return the value attached to the specified edge.
|
java.util.List<E> |
getEdgeObjects(int v1,
int v2)
Return a
List containing the values attached to the edges between the vertices v1 and v2. |
java.util.stream.Stream<E> |
getEdgeObjectStream()
Return a
Stream to iterate over the values attached to the edges. |
int[] |
getEdges()
Return the indices of the edges.
|
java.lang.Iterable<E> |
getEdgesObject()
Return an
Iterable to iterate over the values attached to the edges. |
int |
getEdgeVertex1(int e)
Return the index of the first vertex that the specified edge is connected to.
|
int |
getEdgeVertex2(int e)
Return the index of the second vertex that the specified edge is connected to.
|
default int |
getMaxVertex()
Deprecated.
Use
getVertexCapacity() instead. |
default int |
getVertexCapacity()
Return the maximum number of vertices that this graph can contain.
|
int |
getVertexCount()
Return the number of vertices.
|
V |
getVertexObject(int v)
Return the value attached to the specified vertex.
|
java.util.stream.Stream<V> |
getVertexObjectStream()
Return a
Stream to iterate over the values attached to the vertices. |
int[] |
getVertices()
Return the indices of the vertices.
|
java.lang.Iterable<V> |
getVerticesObj()
Return an
Iterable to iterate over the values attached to the vertices. |
void |
print(java.io.PrintStream out,
java.util.function.Function<V,java.lang.String> vertexToString,
java.util.function.Function<E,java.lang.String> edgeToString)
Prints the entire graph to the specified
PrintStream . |
void |
removeAllEdges()
Remove all the edges and notify the
UndirectedGraphListener s. |
void |
removeAllVertices()
Remove all the vertices of this graph.
|
E |
removeEdge(int e)
Remove the specified edge and notify the
UndirectedGraphListener s. |
void |
removeListener(UndirectedGraphListener l)
Remove a
UndirectedGraphListener to stop listening the graph changes. |
V |
removeVertex(int v)
Remove the specified vertex and notify the
UndirectedGraphListener s. |
void |
setVertexObject(int v,
V obj)
Set the value attached to the specified vertex.
|
void |
traverse(int v,
Traverser traverser)
Traverse the entire graph, starting at the specified vertex v.
|
void |
traverse(int v,
Traverser traverser,
boolean[] encountered)
Traverse the entire graph, starting at the specified vertex v.
|
int addVertex()
UndirectedGraphListener
s.V removeVertex(int v)
UndirectedGraphListener
s.
This method throws a PowsyblException
if the vertex doesn't exist or if an edge is connected to this vertex.v
- the vertex index to remove.int getVertexCount()
int addEdge(int v1, int v2, E obj)
UndirectedGraphListener
s.
This method throws a PowsyblException
if one of the vertices doesn't exist.v1
- the first end of the edge.v2
- the second end of the edge.obj
- the value attached to the edge.E removeEdge(int e)
UndirectedGraphListener
s.
This method thows a PowsyblException
if the edge doesn't exist.e
- the edge index to remove.void removeAllEdges()
UndirectedGraphListener
s.int getEdgeCount()
int[] getEdges()
int[] getVertices()
@Deprecated default int getMaxVertex()
getVertexCapacity()
instead.getVertices()
instead.
To get the number of vertices in this graph, use getVertexCount()
.default int getVertexCapacity()
getVertices()
instead.
To get the number of vertices in this graph, use getVertexCount()
.java.lang.Iterable<V> getVerticesObj()
Iterable
to iterate over the values attached to the vertices.Iterable
to iterate over the values attached to the vertices.java.util.stream.Stream<V> getVertexObjectStream()
Stream
to iterate over the values attached to the vertices.Stream
to iterate over the values attached to the vertices.V getVertexObject(int v)
PowsyblException
if the vertex doesn't exist.v
- the vertex indexvoid setVertexObject(int v, V obj)
PowsyblException
if the vertex doesn't exist.v
- the vertex index.obj
- the value to attach to the vertex.int getEdgeVertex1(int e)
PowsyblException
if the edge doesn't exist.e
- the edge index.int getEdgeVertex2(int e)
PowsyblException
if the edge doesn't exist.e
- the edge index.void removeAllVertices()
PowsyblException
if edges exist.java.lang.Iterable<E> getEdgesObject()
Iterable
to iterate over the values attached to the edges.Iterable
to iterate over the values attached to the edges.java.util.stream.Stream<E> getEdgeObjectStream()
Stream
to iterate over the values attached to the edges.Stream
to iterate over the values attached to the edges.E getEdgeObject(int e)
e
- the index of an edge.java.util.List<E> getEdgeObjects(int v1, int v2)
List
containing the values attached to the edges between the vertices v1 and v2.List
containing the values attached to the edges between the vertices v1 and v2.void traverse(int v, Traverser traverser, boolean[] encountered)
Traverser
instance to know if the traverse of the graph should continue or stop.
This method throws a PowsyblException
if the encountered table size is less than the maximum vertex index.
At the end of the method, the encountered array contains true for all the traversed vertices, false otherwise.v
- the vertex index where the traverse has to start.traverser
- the Traverser
instance to use to know if the traverse should continue or stop.encountered
- the list of traversed vertices.void traverse(int v, Traverser traverser)
traverse(int, Traverser, boolean[])
.v
- the vertex index where the traverse has to start.traverser
- the Traverser
instance to use to know if the traverse should continue or stop.java.util.List<gnu.trove.list.array.TIntArrayList> findAllPaths(int from, java.util.function.Function<V,java.lang.Boolean> pathComplete, java.util.function.Function<E,java.lang.Boolean> pathCancelled)
from
- the vertex index where the traverse has to start.pathComplete
- a function that returns true when the target vertex is found.pathCancelled
- a function that returns true when the edge must not be traversed.void addListener(UndirectedGraphListener l)
UndirectedGraphListener
to get notified when the graph changes.l
- the listener to add.void removeListener(UndirectedGraphListener l)
UndirectedGraphListener
to stop listening the graph changes.l
- the listener to remove.void print(java.io.PrintStream out, java.util.function.Function<V,java.lang.String> vertexToString, java.util.function.Function<E,java.lang.String> edgeToString)
PrintStream
.
The printing relies on the two specified functions to render the values attached to a vertex or an edge.out
- the output stream.vertexToString
- the function to use to render the values of vertices.edgeToString
- the function to use to render the values of edges.Copyright © 2019. All rights reserved.