public class Graph<T>
extends java.util.AbstractCollection<T>
getSortedVertices()
method.Modifier and Type | Class and Description |
---|---|
static class |
Graph.Cycle |
static class |
Graph.CycleException |
class |
Graph.Visitor |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<T,oracle.javatools.util.Graph.Vertex<T>> |
_vertices |
Constructor and Description |
---|
Graph() |
Graph(java.util.Collection<T> vertices)
Constructs a graph containing all elements in the specified collection
as vertices.
|
Graph(Graph<T> original)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(T vertex)
Adds a vertex to the graph.
|
void |
connect(T from,
T to)
Creates a connection between two vertices.
|
boolean |
contains(java.lang.Object vertex) |
java.util.Comparator<T> |
createComparator()
Creates a comparator that can be used to compare any two items in the
graph based on their sorted order (i.e.
|
void |
dfs(T start,
boolean direction,
Graph.Visitor visitor) |
java.util.List<Graph.Cycle> |
findCycles() |
java.util.List<T> |
findElementaryCycle(Graph.Cycle cycle) |
java.lang.String |
getCycleMessage(java.util.List<Graph.Cycle> cycles) |
java.lang.String |
getElementaryCycleMessage(java.util.List<Graph.Cycle> cycles)
Returns the list of elementary cycles found, in the form of a numbered
list suitable for displaying in an IDE dialog.
|
java.util.List<T> |
getInwardEdges(T to)
Returns the list of vertices that a connects to a specified vertex.
|
java.util.List<T> |
getOutwardEdges(T from)
Returns the list of vertices that a specified vertex connects to.
|
java.util.List<T> |
getSortedVertices()
Get an ordered list of vertices, sorted such that for any given vertex
A with a directed edge to vertex B, index(B) < index(A).
|
java.util.List<T> |
getSortedVertices(T startVertex)
Get an ordered list of vertices, sorted such that for any given vertex
A with a directed edge to vertex B, index(B) < index(A).
|
java.util.List<T> |
getVerticesConnectedTo(T vertex)
Get all vertices connected to the specified vertex.
|
java.util.Iterator<T> |
iterator()
Returns an iterator over the vertices in this graph.
|
boolean |
remove(java.lang.Object vertex) |
int |
size() |
Graph<T> |
subgraph(java.util.Collection<T> vertices)
Returns a new graph containing only the specified vertices.
|
static <Z> Graph<Z> |
unmodifiableGraph(Graph<? extends Z> graph)
Returns a graph based on the specified graph, but which does not permit
modification.
|
addAll, clear, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
public Graph(Graph<T> original)
original
- a graph to copy.public Graph()
public Graph(java.util.Collection<T> vertices)
vertices
- vertices to add to the collection. Note that, per the
general contract of Collection.add(E)
, the collection must not contain
any duplicate elements. If it does, this constructor will throw an
IllegalArgumentException.public void dfs(T start, boolean direction, Graph.Visitor visitor)
public java.util.Comparator<T> createComparator() throws Graph.CycleException
#getSortedVertices(T)
method).The returned Comparator is not live-connected to the graph. If you make changes to the graph after retrieving a comparator, the comparator will no longer be correct.
Graph.CycleException
public boolean contains(java.lang.Object vertex)
public boolean add(T vertex)
public void connect(T from, T to)
from
- a vertex at the "from" end of a directed connection. The
vertex must be added first using add(T)
.to
- a vertex at the "to" end of a directed connection. The
vertex must be added first using add(T)
.java.lang.IllegalArgumentException
- if you attempt to connect a vertex to itself,
i.e. if from == to.public java.util.List<T> getOutwardEdges(T from)
from
- a vertex that must be in the graph.public java.util.List<T> getInwardEdges(T to)
to
- a vertex that must be in the graph.public Graph<T> subgraph(java.util.Collection<T> vertices)
vertices
- a collection of vertices to retain.public java.util.List<Graph.Cycle> findCycles()
public java.util.List<T> findElementaryCycle(Graph.Cycle cycle)
public java.lang.String getCycleMessage(java.util.List<Graph.Cycle> cycles)
cycles
- the list returned by findCycles()public java.lang.String getElementaryCycleMessage(java.util.List<Graph.Cycle> cycles)
cycles
- the list returned by findCycles()public java.util.Iterator<T> iterator()
public boolean remove(java.lang.Object vertex)
public int size()
public java.util.List<T> getSortedVertices() throws Graph.CycleException
Graph.CycleException
public java.util.List<T> getSortedVertices(T startVertex) throws Graph.CycleException
In a dependency graph, this method essentially returns all of the downstream dependencies of the given vertex in an order which satisfies the dependencies.
The first vertex in the returned list will always be startVertex.
startVertex
- the vertex to start from. If you pass null, this
method will behave exactly the same as getSortedVertices()
.Graph.CycleException
public java.util.List<T> getVerticesConnectedTo(T vertex) throws Graph.CycleException
vertex
- a vertex. Must not be null.Graph.CycleException
public static <Z> Graph<Z> unmodifiableGraph(Graph<? extends Z> graph)
graph
- the original graph.