com.google.javascript.jscomp.graph.DiGraph Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of closure-compiler-linter Show documentation
Show all versions of closure-compiler-linter Show documentation
Closure Compiler is a JavaScript optimizing compiler. It parses your
JavaScript, analyzes it, removes dead code and rewrites and minimizes
what's left. It also checks syntax, variable references, and types, and
warns about common JavaScript pitfalls. It is used in many of Google's
JavaScript apps, including Gmail, Google Web Search, Google Maps, and
Google Docs.
This binary checks for style issues such as incorrect or missing JSDoc
usage, and missing goog.require() statements. It does not do more advanced
checks such as typechecking.
/*
* Copyright 2008 The Closure Compiler Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.javascript.jscomp.graph;
import java.util.Collection;
import java.util.List;
/**
* A generic directed graph.
*
*
* @param Value type that the graph node stores.
* @param Value type that the graph edge stores.
*/
public abstract class DiGraph extends Graph {
@Override
public abstract DiGraphNode createNode(N nodeValue);
@Override
public abstract Collection extends DiGraphNode> getNodes();
@Override
public abstract DiGraphNode getNode(N nodeValue);
@Override
public abstract List extends DiGraphEdge> getEdges();
@Override
public abstract List extends DiGraphEdge> getEdges(N n1, N n2);
public abstract List extends DiGraphEdge> getEdgesInDirection(N n1, N n2);
/** Gets an immutable list of out edges of the given node. */
public abstract List extends DiGraphEdge> getOutEdges(N nodeValue);
/** Gets an immutable list of in edges of the given node. */
public abstract List extends DiGraphEdge> getInEdges(N nodeValue);
public abstract List extends DiGraphNode> getDirectedPredNodes(DiGraphNode n);
public abstract List extends DiGraphNode> getDirectedPredNodes(N nodeValue);
public abstract List extends DiGraphNode> getDirectedSuccNodes(DiGraphNode n);
public abstract List extends DiGraphNode> getDirectedSuccNodes(N nodeValue);
/**
* Disconnects all edges from n1 to n2.
*
* @param n1 Source node.
* @param n2 Destination node.
*/
public abstract void disconnectInDirection(N n1, N n2);
/**
* Checks whether two nodes in the graph are connected via a directed edge.
*
* @param n1 Node 1.
* @param n2 Node 2.
* @return true
if the graph contains edge from n1 to n2.
*/
public abstract boolean isConnectedInDirection(N n1, N n2);
/**
* Checks whether two nodes in the graph are connected via a directed edge
* with the given value.
*
* @param n1 Node 1.
* @param edgeValue edge value tag
* @param n2 Node 2.
* @return true
if the edge exists.
*/
public abstract boolean isConnectedInDirection(N n1, E edgeValue, N n2);
@Override
public boolean isConnected(N n1, N n2) {
return isConnectedInDirection(n1, n2) || isConnectedInDirection(n2, n1);
}
@Override
public boolean isConnected(N n1, E e, N n2) {
return isConnectedInDirection(n1, e, n2) ||
isConnectedInDirection(n2, e, n1);
}
/**
* A generic directed graph node.
*
* @param Value type that the graph node stores.
* @param Value type that the graph edge stores.
*/
public static interface DiGraphNode extends GraphNode {
public List extends DiGraphEdge> getOutEdges();
public List extends DiGraphEdge> getInEdges();
}
/**
* A generic directed graph edge.
*
* @param Value type that the graph node stores.
* @param Value type that the graph edge stores.
*/
public static interface DiGraphEdge extends GraphEdge {
public DiGraphNode getSource();
public DiGraphNode getDestination();
}
}