V - type of vertexpublic class DirectedGraph<V> extends Object
Graph uses LinkedHashSet to preserve the order of vertices and edges.
| Constructor and Description |
|---|
DirectedGraph()
Creates new instance of
DirectedGraph with no vertices and edges. |
DirectedGraph(Collection<? extends V> vertices)
Creates new instance of
DirectedGraph with given vertices and no
edges. |
DirectedGraph(Collection<? extends V> vertices,
Collection<Edge<V>> edges)
Creates new instance of
DirectedGraph with given vertices and
edges. |
DirectedGraph(DirectedGraph<V> graph)
Creates new instance of
DirectedGraph as a copy of given graph. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEdge(Edge<V> edge)
Adds given edge to this graph.
|
void |
addEdge(V source,
V target)
Creates and adds an edge to this graph.
|
void |
addEdges(Collection<Edge<V>> edges)
Adds a collection of edges to this graph.
|
void |
addVertex(V vertex)
Adds given vertex to this graph.
|
boolean |
containsEdge(Edge<V> edge)
Returns true if this graph contains given edge.
|
boolean |
containsVertex(V vertex)
Returns true if this graph contains given vertex.
|
boolean |
equals(Object obj)
Returns true if
obj is DirectedGraph and has equal set of
vertices and edges. |
int |
getDegree(V vertex)
Returns sum of in and out degree of given vertex.
|
int |
getEdgeCount()
Returns count of edges.
|
Set<Edge<V>> |
getEdges()
Returns unmodifiable set of edges backed by this graph.
|
Set<Edge<V>> |
getEdgesConnectedTo(V vertex)
Returns edges with given vertex as source of target.
|
Set<Edge<V>> |
getEdgesFrom(V vertex)
Returns unmodifiable set of edges with given vertex as source backed by
this graph.
|
Set<Edge<V>> |
getEdgesTo(V vertex)
Returns unmodifiable set of edges with given vertex as target backed by
this graph.
|
int |
getInDegree(V vertex)
Returns in degree of given vertex.
|
int |
getOutDegree(V vertex)
Returns out degree of given vertex.
|
int |
getVertexCount()
Returns count of vertices.
|
Set<V> |
getVertices()
Returns unmodifiable set of vertices backed by this graph.
|
int |
hashCode() |
void |
removeEdge(Edge<V> edge)
Removes given edge from this graph.
|
void |
removeEdges(Collection<Edge<V>> edges)
Removes all given edges from this graph.
|
void |
removeVertex(V vertex)
Removes given vertex from this graph and all its edges.
|
String |
toString() |
public DirectedGraph()
DirectedGraph with no vertices and edges.public DirectedGraph(Collection<? extends V> vertices)
DirectedGraph with given vertices and no
edges.vertices - vertex collectionpublic DirectedGraph(DirectedGraph<V> graph)
DirectedGraph as a copy of given graph.graph - graph to copypublic DirectedGraph(Collection<? extends V> vertices, Collection<Edge<V>> edges)
DirectedGraph with given vertices and
edges.vertices - vertex collectionedges - edge collectionpublic final void addVertex(V vertex)
vertex - vertex to addNullPointerException - if vertex is nullpublic final void removeVertex(V vertex)
vertex - vertex to removepublic final boolean containsVertex(V vertex)
vertex - vertexpublic final void addEdge(Edge<V> edge)
edge - edge to addNullPointerException - if edge is nullIllegalArgumentException - if edge connects not existing verticespublic final void addEdges(Collection<Edge<V>> edges)
edges - public final void addEdge(V source, V target)
source - a source vertextarget - a target vertexNullPointerException - if edge is nullIllegalArgumentException - if edge connects not existing verticespublic final void removeEdge(Edge<V> edge)
edge - edge to removepublic final void removeEdges(Collection<Edge<V>> edges)
edges - public final boolean containsEdge(Edge<V> edge)
edge - edgepublic final Set<Edge<V>> getEdgesFrom(V vertex)
vertex - source vertexpublic final Set<Edge<V>> getEdgesTo(V vertex)
vertex - target vertexpublic final Set<Edge<V>> getEdgesConnectedTo(V vertex)
vertex - vertexpublic final int getOutDegree(V vertex)
vertex - public final int getInDegree(V vertex)
vertex - public final int getDegree(V vertex)
vertex - public final Set<V> getVertices()
public final Set<Edge<V>> getEdges()
public final int getVertexCount()
public final int getEdgeCount()
public int hashCode()
hashCode in class ObjectObject.hashCode()public boolean equals(Object obj)
obj is DirectedGraph and has equal set of
vertices and edges.equals in class ObjectObject.equals(java.lang.Object)public String toString()
toString in class ObjectObject.toString()Copyright © 2007-2020 Whitestein Technologies. All Rights Reserved.