public class GraphDecorator<V,E> extends Object implements Graph<V,E>, Serializable
Graph that delegates its method calls to a
constructor-specified Graph instance. This is useful for adding
additional behavior (such as synchronization or unmodifiability) to an existing
instance.| Constructor and Description |
|---|
GraphDecorator(Graph<V,E> delegate)
Creates a new instance based on the provided
delegate. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdge(E edge,
Collection<? extends V> vertices)
Adds
edge to this graph. |
boolean |
addEdge(E edge,
Collection<? extends V> vertices,
EdgeType edge_type)
Adds
edge to this graph with type edge_type. |
boolean |
addEdge(E e,
V v1,
V v2)
Adds edge
e to this graph such that it connects
vertex v1 to v2. |
boolean |
addEdge(E e,
V v1,
V v2,
EdgeType edgeType)
Adds edge
e to this graph such that it connects
vertex v1 to v2. |
boolean |
addVertex(V vertex)
Adds
vertex to this graph. |
boolean |
containsEdge(E edge)
Returns true if this graph's edge collection contains
edge. |
boolean |
containsVertex(V vertex)
Returns true if this graph's vertex collection contains
vertex. |
int |
degree(V vertex)
Returns the number of edges incident to
vertex. |
E |
findEdge(V v1,
V v2)
Returns an edge that connects this vertex to
v. |
Collection<E> |
findEdgeSet(V v1,
V v2)
Returns all edges that connects this vertex to
v. |
EdgeType |
getDefaultEdgeType()
Returns the default edge type for this graph.
|
V |
getDest(E directed_edge)
If
directed_edge is a directed edge in this graph, returns the destination;
otherwise returns null. |
int |
getEdgeCount()
Returns the number of edges in this graph.
|
int |
getEdgeCount(EdgeType edge_type)
Returns the number of edges of type
edge_type in this graph. |
Collection<E> |
getEdges()
Returns a view of all edges in this graph.
|
Collection<E> |
getEdges(EdgeType edgeType)
Returns the collection of edges in this graph which are of type
edge_type. |
EdgeType |
getEdgeType(E edge)
Returns the edge type of
edge in this graph. |
Pair<V> |
getEndpoints(E edge)
Returns the endpoints of
edge as a Pair. |
int |
getIncidentCount(E edge)
Returns the number of vertices that are incident to
edge. |
Collection<E> |
getIncidentEdges(V vertex)
Returns the collection of edges in this graph which are connected to
vertex. |
Collection<V> |
getIncidentVertices(E edge)
Returns the collection of vertices in this graph which are connected to
edge. |
Collection<E> |
getInEdges(V vertex)
Returns a
Collection view of the incoming edges incident to vertex
in this graph. |
int |
getNeighborCount(V vertex)
Returns the number of vertices that are adjacent to
vertex
(that is, the number of vertices that are incident to edges in vertex's
incident edge set). |
Collection<V> |
getNeighbors(V vertex)
Returns the collection of vertices which are connected to
vertex
via any edges in this graph. |
V |
getOpposite(V vertex,
E edge)
Returns the vertex at the other end of
edge from vertex. |
Collection<E> |
getOutEdges(V vertex)
Returns a
Collection view of the outgoing edges incident to vertex
in this graph. |
int |
getPredecessorCount(V vertex)
Returns the number of predecessors that
vertex has in this graph. |
Collection<V> |
getPredecessors(V vertex)
Returns a
Collection view of the predecessors of vertex
in this graph. |
V |
getSource(E directed_edge)
If
directed_edge is a directed edge in this graph, returns the source;
otherwise returns null. |
int |
getSuccessorCount(V vertex)
Returns the number of successors that
vertex has in this graph. |
Collection<V> |
getSuccessors(V vertex)
Returns a
Collection view of the successors of vertex
in this graph. |
int |
getVertexCount()
Returns the number of vertices in this graph.
|
Collection<V> |
getVertices()
Returns a view of all vertices in this graph.
|
int |
inDegree(V vertex)
Returns the number of incoming edges incident to
vertex. |
boolean |
isDest(V vertex,
E edge)
Returns
true if vertex is the destination of edge. |
boolean |
isIncident(V vertex,
E edge)
Returns
true if vertex and edge
are incident to each other. |
boolean |
isNeighbor(V v1,
V v2)
Returns
true if v1 and v2 share an incident edge. |
boolean |
isPredecessor(V v1,
V v2)
Returns
true if v1 is a predecessor of v2 in this graph. |
boolean |
isSource(V vertex,
E edge)
Returns
true if vertex is the source of edge. |
boolean |
isSuccessor(V v1,
V v2)
Returns
true if v1 is a successor of v2 in this graph. |
int |
outDegree(V vertex)
Returns the number of outgoing edges incident to
vertex. |
boolean |
removeEdge(E edge)
Removes
edge from this graph. |
boolean |
removeVertex(V vertex)
Removes
vertex from this graph. |
public boolean addEdge(E edge, Collection<? extends V> vertices)
Hypergraphedge to this graph.
Fails under the following circumstances:
edge is already an element of the graph
edge or vertices is null
vertices has the wrong number of vertices for the graph type
vertices are already connected by another edge in this graph,
and this graph does not accept parallel edges
addEdge in interface Hypergraph<V,E>edge - the edge to addvertices - the vertices to which the edge will be connectedtrue if the add is successful, and false otherwiseHypergraph.addEdge(java.lang.Object, java.util.Collection)public boolean addEdge(E edge, Collection<? extends V> vertices, EdgeType edge_type)
Hypergraphedge to this graph with type edge_type.
Fails under the following circumstances:
edge is already an element of the graph
edge or vertices is null
vertices has the wrong number of vertices for the graph type
vertices are already connected by another edge in this graph,
and this graph does not accept parallel edges
edge_type is not legal for this graph
addEdge in interface Hypergraph<V,E>edge - edge to add to this graphvertices - vertices which are to be connected by this edgeedge_type - type of edge to addtrue if the add is successful, and false otherwiseHypergraph.addEdge(Object, Collection, EdgeType)public boolean addEdge(E e, V v1, V v2, EdgeType edgeType)
Graphe to this graph such that it connects
vertex v1 to v2.
Equivalent to addEdge(e, new Pair(v1, v2)).
If this graph does not contain v1, v2,
or both, implementations may choose to either silently add
the vertices to the graph or throw an IllegalArgumentException.
If edgeType is not legal for this graph, this method will
throw IllegalArgumentException.
See Hypergraph.addEdge() for a listing of possible reasons
for failure.addEdge in interface Graph<V,E>e - the edge to be addedv1 - the first vertex to be connectedv2 - the second vertex to be connectededgeType - the type to be assigned to the edgetrue if the add is successful, false otherwiseGraph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object, edu.uci.ics.jung.graph.util.EdgeType)public boolean addEdge(E e, V v1, V v2)
Graphe to this graph such that it connects
vertex v1 to v2.
Equivalent to addEdge(e, new Pair(v1, v2)).
If this graph does not contain v1, v2,
or both, implementations may choose to either silently add
the vertices to the graph or throw an IllegalArgumentException.
If this graph assigns edge types to its edges, the edge type of
e will be the default for this graph.
See Hypergraph.addEdge() for a listing of possible reasons
for failure.addEdge in interface Graph<V,E>e - the edge to be addedv1 - the first vertex to be connectedv2 - the second vertex to be connectedtrue if the add is successful, false otherwiseGraph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object)public boolean addVertex(V vertex)
Hypergraphvertex to this graph.
Fails if vertex is null or already in the graph.addVertex in interface Hypergraph<V,E>vertex - the vertex to addtrue if the add is successful, and false otherwiseHypergraph.addVertex(java.lang.Object)public boolean isIncident(V vertex, E edge)
Hypergraphtrue if vertex and edge
are incident to each other.
Equivalent to getIncidentEdges(vertex).contains(edge) and to
getIncidentVertices(edge).contains(vertex).isIncident in interface Hypergraph<V,E>vertex - vertex to testedge - edge to testtrue if vertex and edge
are incident to each otherHypergraph.isIncident(java.lang.Object, java.lang.Object)public boolean isNeighbor(V v1, V v2)
Hypergraphtrue if v1 and v2 share an incident edge.
Equivalent to getNeighbors(v1).contains(v2).isNeighbor in interface Hypergraph<V,E>v1 - the first vertex to testv2 - the second vertex to testtrue if v1 and v2 share an incident edgeHypergraph.isNeighbor(java.lang.Object, java.lang.Object)public int degree(V vertex)
Hypergraphvertex.
Special cases of interest:
getNeighborCount).
Equivalent to getIncidentEdges(vertex).size().
degree in interface Hypergraph<V,E>vertex - the vertex whose degree is to be returnedHypergraph.degree(java.lang.Object)public E findEdge(V v1, V v2)
Hypergraphv.
If this edge is not uniquely
defined (that is, if the graph contains more than one edge connecting
v1 to v2), any of these edges
may be returned. findEdgeSet(v1, v2) may be
used to return all such edges.
Returns null if either of the following is true:
v2 is not connected to v1
v1 or v2 are not present in this graph
Note: for purposes of this method, v1 is only considered to be connected to
v2 via a given directed edge e if
v1 == e.getSource() && v2 == e.getDest() evaluates to true.
(v1 and v2 are connected by an undirected edge u if
u is incident to both v1 and v2.)
findEdge in interface Hypergraph<V,E>v1 - the first endpoint of the returned edgev2 - the second endpoint of the returned edgev1 to v2,
or null if no such edge exists (or either vertex is not present)Hypergraph.findEdge(java.lang.Object, java.lang.Object)public Collection<E> findEdgeSet(V v1, V v2)
Hypergraphv.
If this edge is not uniquely
defined (that is, if the graph contains more than one edge connecting
v1 to v2), any of these edges
may be returned. findEdgeSet(v1, v2) may be
used to return all such edges.
Returns null if v2 is not connected to v1.
v1 or v2
are not present in this graph.
Note: for purposes of this method, v1 is only considered to be connected to
v2 via a given directed edge d if
v1 == d.getSource() && v2 == d.getDest() evaluates to true.
(v1 and v2 are connected by an undirected edge u if
u is incident to both v1 and v2.)
findEdgeSet in interface Hypergraph<V,E>v1 - the first endpoint of the returned edge setv2 - the second endpoint of the returned edge setv1 to v2,
or null if either vertex is not presentHypergraph.findEdgeSet(java.lang.Object, java.lang.Object)public V getDest(E directed_edge)
Graphdirected_edge is a directed edge in this graph, returns the destination;
otherwise returns null.
The destination of a directed edge d is defined to be the vertex
incident to d for which
d is an incoming edge.
directed_edge is guaranteed to be a directed edge if
its EdgeType is DIRECTED.getDest in interface Graph<V,E>getDest in interface Hypergraph<V,E>directed_edge - the edge whose destination is to be returneddirected_edge if it is a directed edge in this graph, or null otherwiseGraph.getDest(java.lang.Object)public int getEdgeCount()
HypergraphgetEdgeCount in interface Hypergraph<V,E>Hypergraph.getEdgeCount()public int getEdgeCount(EdgeType edge_type)
Hypergraphedge_type in this graph.getEdgeCount in interface Hypergraph<V,E>edge_type - the type of edge for which the count is to be returnededge_type in this graphHypergraph.getEdgeCount(EdgeType)public Collection<E> getEdges()
HypergraphCollection contract, and therefore makes no guarantees
about the ordering of the vertices within the set.getEdges in interface Hypergraph<V,E>Collection view of all edges in this graphHypergraph.getEdges()public Collection<E> getEdges(EdgeType edgeType)
Hypergraphedge_type.getEdges in interface Hypergraph<V,E>edgeType - the type of edges to be returnededge_type, or
null if the graph does not accept edges of this typeHypergraph.getEdges(edu.uci.ics.jung.graph.util.EdgeType)public EdgeType getEdgeType(E edge)
Hypergraphedge in this graph.getEdgeType in interface Hypergraph<V,E>edge - the edge whose type is to be returnedEdgeType of edge, or null if edge has no defined typeHypergraph.getEdgeType(java.lang.Object)public EdgeType getDefaultEdgeType()
HypergraphgetDefaultEdgeType in interface Hypergraph<V,E>Hypergraph.getDefaultEdgeType()public Pair<V> getEndpoints(E edge)
Graphedge as a Pair.getEndpoints in interface Graph<V,E>edge - the edge whose endpoints are to be returnededgeGraph.getEndpoints(java.lang.Object)public int getIncidentCount(E edge)
Hypergraphedge.
For hyperedges, this can be any nonnegative integer; for edges this
must be 2 (or 1 if self-loops are permitted).
Equivalent to getIncidentVertices(edge).size().
getIncidentCount in interface Hypergraph<V,E>edge - the edge whose incident vertex count is to be returnededge.Hypergraph.getIncidentCount(java.lang.Object)public Collection<E> getIncidentEdges(V vertex)
Hypergraphvertex.getIncidentEdges in interface Hypergraph<V,E>vertex - the vertex whose incident edges are to be returnedvertex,
or null if vertex is not presentHypergraph.getIncidentEdges(java.lang.Object)public Collection<V> getIncidentVertices(E edge)
Hypergraphedge.
Note that for some graph types there are guarantees about the size of this collection
(i.e., some graphs contain edges that have exactly two endpoints, which may or may
not be distinct). Implementations for those graph types may provide alternate methods
that provide more convenient access to the vertices.getIncidentVertices in interface Hypergraph<V,E>edge - the edge whose incident vertices are to be returnededge,
or null if edge is not presentHypergraph.getIncidentVertices(java.lang.Object)public Collection<E> getInEdges(V vertex)
GraphCollection view of the incoming edges incident to vertex
in this graph.getInEdges in interface Graph<V,E>getInEdges in interface Hypergraph<V,E>vertex - the vertex whose incoming edges are to be returnedCollection view of the incoming edges incident
to vertex in this graphGraph.getInEdges(java.lang.Object)public int getNeighborCount(V vertex)
Hypergraphvertex
(that is, the number of vertices that are incident to edges in vertex's
incident edge set).
Equivalent to getNeighbors(vertex).size().
getNeighborCount in interface Hypergraph<V,E>vertex - the vertex whose neighbor count is to be returnedHypergraph.getNeighborCount(java.lang.Object)public Collection<V> getNeighbors(V vertex)
Hypergraphvertex
via any edges in this graph.
If vertex is connected to itself with a self-loop, then
it will be included in the collection returned.getNeighbors in interface Hypergraph<V,E>vertex - the vertex whose neighbors are to be returnedvertex,
or null if vertex is not presentHypergraph.getNeighbors(java.lang.Object)public V getOpposite(V vertex, E edge)
Graphedge from vertex.
(That is, returns the vertex incident to edge which is not vertex.)getOpposite in interface Graph<V,E>vertex - the vertex to be queriededge - the edge to be queriededge from vertexGraph.getOpposite(java.lang.Object, java.lang.Object)public Collection<E> getOutEdges(V vertex)
GraphCollection view of the outgoing edges incident to vertex
in this graph.getOutEdges in interface Graph<V,E>getOutEdges in interface Hypergraph<V,E>vertex - the vertex whose outgoing edges are to be returnedCollection view of the outgoing edges incident
to vertex in this graphGraph.getOutEdges(java.lang.Object)public int getPredecessorCount(V vertex)
Graphvertex has in this graph.
Equivalent to vertex.getPredecessors().size().getPredecessorCount in interface Graph<V,E>vertex - the vertex whose predecessor count is to be returnedvertex has in this graphGraph.getPredecessorCount(java.lang.Object)public Collection<V> getPredecessors(V vertex)
GraphCollection view of the predecessors of vertex
in this graph. A predecessor of vertex is defined as a vertex v
which is connected to
vertex by an edge e, where e is an outgoing edge of
v and an incoming edge of vertex.getPredecessors in interface Graph<V,E>getPredecessors in interface Hypergraph<V,E>vertex - the vertex whose predecessors are to be returnedCollection view of the predecessors of
vertex in this graphGraph.getPredecessors(java.lang.Object)public V getSource(E directed_edge)
Graphdirected_edge is a directed edge in this graph, returns the source;
otherwise returns null.
The source of a directed edge d is defined to be the vertex for which
d is an outgoing edge.
directed_edge is guaranteed to be a directed edge if
its EdgeType is DIRECTED.getSource in interface Graph<V,E>getSource in interface Hypergraph<V,E>directed_edge - the edge whose source is to be returneddirected_edge if it is a directed edge in this graph, or null otherwiseGraph.getSource(java.lang.Object)public int getSuccessorCount(V vertex)
Graphvertex has in this graph.
Equivalent to vertex.getSuccessors().size().getSuccessorCount in interface Graph<V,E>vertex - the vertex whose successor count is to be returnedvertex has in this graphGraph.getSuccessorCount(java.lang.Object)public Collection<V> getSuccessors(V vertex)
GraphCollection view of the successors of vertex
in this graph. A successor of vertex is defined as a vertex v
which is connected to
vertex by an edge e, where e is an incoming edge of
v and an outgoing edge of vertex.getSuccessors in interface Graph<V,E>getSuccessors in interface Hypergraph<V,E>vertex - the vertex whose predecessors are to be returnedCollection view of the successors of
vertex in this graphGraph.getSuccessors(java.lang.Object)public int getVertexCount()
HypergraphgetVertexCount in interface Hypergraph<V,E>Hypergraph.getVertexCount()public Collection<V> getVertices()
HypergraphCollection contract, and therefore makes no guarantees
about the ordering of the vertices within the set.getVertices in interface Hypergraph<V,E>Collection view of all vertices in this graphHypergraph.getVertices()public int inDegree(V vertex)
Graphvertex.
Equivalent to getInEdges(vertex).size().inDegree in interface Graph<V,E>inDegree in interface Hypergraph<V,E>vertex - the vertex whose indegree is to be calculatedvertexGraph.inDegree(java.lang.Object)public boolean isDest(V vertex, E edge)
Graphtrue if vertex is the destination of edge.
Equivalent to getDest(edge).equals(vertex).isDest in interface Graph<V,E>vertex - the vertex to be queriededge - the edge to be queriedtrue iff vertex is the destination of edgeGraph.isDest(java.lang.Object, java.lang.Object)public boolean isPredecessor(V v1, V v2)
Graphtrue if v1 is a predecessor of v2 in this graph.
Equivalent to v1.getPredecessors().contains(v2).isPredecessor in interface Graph<V,E>v1 - the first vertex to be queriedv2 - the second vertex to be queriedtrue if v1 is a predecessor of v2, and false otherwise.Graph.isPredecessor(java.lang.Object, java.lang.Object)public boolean isSource(V vertex, E edge)
Graphtrue if vertex is the source of edge.
Equivalent to getSource(edge).equals(vertex).isSource in interface Graph<V,E>vertex - the vertex to be queriededge - the edge to be queriedtrue iff vertex is the source of edgeGraph.isSource(java.lang.Object, java.lang.Object)public boolean isSuccessor(V v1, V v2)
Graphtrue if v1 is a successor of v2 in this graph.
Equivalent to v1.getSuccessors().contains(v2).isSuccessor in interface Graph<V,E>v1 - the first vertex to be queriedv2 - the second vertex to be queriedtrue if v1 is a successor of v2, and false otherwise.Graph.isSuccessor(java.lang.Object, java.lang.Object)public int outDegree(V vertex)
Graphvertex.
Equivalent to getOutEdges(vertex).size().outDegree in interface Graph<V,E>outDegree in interface Hypergraph<V,E>vertex - the vertex whose outdegree is to be calculatedvertexGraph.outDegree(java.lang.Object)public boolean removeEdge(E edge)
Hypergraphedge from this graph.
Fails if edge is null, or is otherwise not an element of this graph.removeEdge in interface Hypergraph<V,E>edge - the edge to removetrue if the removal is successful, false otherwiseHypergraph.removeEdge(java.lang.Object)public boolean removeVertex(V vertex)
Hypergraphvertex from this graph.
As a side effect, removes any edges e incident to vertex if the
removal of vertex would cause e to be incident to an illegal
number of vertices. (Thus, for example, incident hyperedges are not removed, but
incident edges--which must be connected to a vertex at both endpoints--are removed.)
Fails under the following circumstances:
vertex is not an element of this graph
vertex is null
removeVertex in interface Hypergraph<V,E>vertex - the vertex to removetrue if the removal is successful, false otherwiseHypergraph.removeVertex(java.lang.Object)public boolean containsEdge(E edge)
Hypergraphedge.
Equivalent to getEdges().contains(edge).containsEdge in interface Hypergraph<V,E>edge - the edge whose presence is being queriededgeHypergraph.containsEdge(java.lang.Object)public boolean containsVertex(V vertex)
Hypergraphvertex.
Equivalent to getVertices().contains(vertex).containsVertex in interface Hypergraph<V,E>vertex - the vertex whose presence is being queriedvertexHypergraph.containsVertex(java.lang.Object)Copyright © 2016. All rights reserved.