All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.javascript.jscomp.graph.DiGraph Maven / Gradle / Ivy

Go to download

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.

There is a newer version: v20240317
Show newest version
/*
 * 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> getNodes();

  @Override
  public abstract DiGraphNode getNode(N nodeValue);

  @Override
  public abstract List> getEdges();

  @Override
  public abstract List> getEdges(N n1, N n2);

  public abstract List> getEdgesInDirection(N n1, N n2);

  /** Gets an immutable list of out edges of the given node. */
  public abstract List> getOutEdges(N nodeValue);

  /** Gets an immutable list of in edges of the given node. */
  public abstract List> getInEdges(N nodeValue);

  public abstract List> getDirectedPredNodes(DiGraphNode n);

  public abstract List> getDirectedPredNodes(N nodeValue);

  public abstract List> getDirectedSuccNodes(DiGraphNode n);

  public abstract List> 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> getOutEdges();

    public List> 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();

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy