Debian Codegraph @

src/com/google/javascript/jscomp/graph/DiGraph.java

raw symbols SCIP
1 /*
2 * Copyright 2008 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp.graph;
18
19 import java.util.List;
20
21 /**
22 * A generic directed graph.
23 *
24 *
25 * @param <N> Value type that the graph node stores.
26 * @param <E> Value type that the graph edge stores.
27 */
28 public abstract class DiGraph<N, E> extends Graph<N, E> {
29
30 /**
31 * Gets an immutable iterable over all the nodes in the graph.
32 */
33 public abstract Iterable<DiGraphNode<N, E>> getDirectedGraphNodes();
34
35 /**
36 * Gets an immutable list of out edges of the given node.
37 */
38 public abstract List<DiGraphEdge<N, E>> getOutEdges(N nodeValue);
39
40 /**
41 * Gets an immutable list of in edges of the given node.
42 */
43 public abstract List<DiGraphEdge<N, E>> getInEdges(N nodeValue);
44
45 public abstract List<DiGraphNode<N, E>> getDirectedPredNodes(
46 DiGraphNode<N, E> n);
47
48 public abstract List<DiGraphNode<N, E>> getDirectedSuccNodes(
49 DiGraphNode<N, E> n);
50
51 public abstract List<DiGraphNode<N, E>>
52 getDirectedPredNodes(N nodeValue);
53
54 public abstract List<DiGraphNode<N, E>>
55 getDirectedSuccNodes(N nodeValue);
56
57 public abstract DiGraphNode<N, E> createDirectedGraphNode(N nodeValue);
58
59 public abstract DiGraphNode<N, E> getDirectedGraphNode(N nodeValue);
60
61 public abstract List<DiGraphEdge<N, E>>
62 getDirectedGraphEdges(N n1, N n2);
63
64 /**
65 * Disconnects all edges from n1 to n2.
66 *
67 * @param n1 Source node.
68 * @param n2 Destination node.
69 */
70 public abstract void disconnectInDirection(N n1, N n2);
71
72 /**
73 * Checks whether two nodes in the graph are connected via a directed edge.
74 *
75 * @param n1 Node 1.
76 * @param n2 Node 2.
77 * @return <code>true</code> if the graph contains edge from n1 to n2.
78 */
79 public abstract boolean isConnectedInDirection(N n1, N n2);
80
81 /**
82 * Checks whether two nodes in the graph are connected via a directed edge
83 * with the given value.
84 *
85 * @param n1 Node 1.
86 * @param edgeValue edge value tag
87 * @param n2 Node 2.
88 * @return <code>true</code> if the edge exists.
89 */
90 public abstract boolean isConnectedInDirection(N n1, E edgeValue, N n2);
91
92 @Override
93 public boolean isConnected(N n1, N n2) {
94 return isConnectedInDirection(n1, n2) || isConnectedInDirection(n2, n1);
95 }
96
97 @Override
98 public boolean isConnected(N n1, E e, N n2) {
99 return isConnectedInDirection(n1, e, n2) ||
100 isConnectedInDirection(n2, e, n1);
101 }
102
103 /**
104 * A generic directed graph node.
105 *
106 * @param <N> Value type that the graph node stores.
107 * @param <E> Value type that the graph edge stores.
108 */
109 public static interface DiGraphNode<N, E> extends GraphNode<N, E> {
110
111 public List<DiGraphEdge<N, E>> getOutEdges();
112
113 public List<DiGraphEdge<N, E>> getInEdges();
114 }
115
116 /**
117 * A generic directed graph edge.
118 *
119 * @param <N> Value type that the graph node stores.
120 * @param <E> Value type that the graph edge stores.
121 */
122 public static interface DiGraphEdge<N, E> extends GraphEdge<N, E> {
123
124 public DiGraphNode<N, E> getSource();
125
126 public DiGraphNode<N, E> getDestination();
127
128 public void setSource(DiGraphNode<N, E> node);
129
130 public void setDestination(DiGraphNode<N, E> node);
131 }
132 }