View Javadoc
1   /*
2    * Copyright (C) 2016 The Guava 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.common.graph;
18  
19  import com.google.errorprone.annotations.CanIgnoreReturnValue;
20  import java.util.Set;
21  
22  /**
23   * An interface for representing and manipulating an origin node's adjacent nodes and incident edges
24   * in a {@link Network}.
25   *
26   * @author James Sexton
27   * @param <N> Node parameter type
28   * @param <E> Edge parameter type
29   */
30  interface NetworkConnections<N, E> {
31  
32    Set<N> adjacentNodes();
33  
34    Set<N> predecessors();
35  
36    Set<N> successors();
37  
38    Set<E> incidentEdges();
39  
40    Set<E> inEdges();
41  
42    Set<E> outEdges();
43  
44    /**
45     * Returns the set of edges connecting the origin node to {@code node}. For networks without
46     * parallel edges, this set cannot be of size greater than one.
47     */
48    Set<E> edgesConnecting(N node);
49  
50    /**
51     * Returns the node that is adjacent to the origin node along {@code edge}.
52     *
53     * <p>In the directed case, {@code edge} is assumed to be an outgoing edge.
54     */
55    N adjacentNode(E edge);
56  
57    /**
58     * Remove {@code edge} from the set of incoming edges. Returns the former predecessor node.
59     *
60     * <p>In the undirected case, returns {@code null} if {@code isSelfLoop} is true.
61     */
62    @CanIgnoreReturnValue
63    N removeInEdge(E edge, boolean isSelfLoop);
64  
65    /** Remove {@code edge} from the set of outgoing edges. Returns the former successor node. */
66    @CanIgnoreReturnValue
67    N removeOutEdge(E edge);
68  
69    /**
70     * Add {@code edge} to the set of incoming edges. Implicitly adds {@code node} as a predecessor.
71     */
72    void addInEdge(E edge, N node, boolean isSelfLoop);
73  
74    /** Add {@code edge} to the set of outgoing edges. Implicitly adds {@code node} as a successor. */
75    void addOutEdge(E edge, N node);
76  }