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  import javax.annotation.Nullable;
22  
23  /**
24   * An interface for representing and manipulating an origin node's adjacent nodes and edge values in
25   * a {@link Graph}.
26   *
27   * @author James Sexton
28   * @param <N> Node parameter type
29   * @param <V> Value parameter type
30   */
31  interface GraphConnections<N, V> {
32  
33    Set<N> adjacentNodes();
34  
35    Set<N> predecessors();
36  
37    Set<N> successors();
38  
39    /**
40     * Returns the value associated with the edge connecting the origin node to {@code node}, or null
41     * if there is no such edge.
42     */
43    @Nullable
44    V value(N node);
45  
46    /** Remove {@code node} from the set of predecessors. */
47    void removePredecessor(N node);
48  
49    /**
50     * Remove {@code node} from the set of successors. Returns the value previously associated with
51     * the edge connecting the two nodes.
52     */
53    @CanIgnoreReturnValue
54    V removeSuccessor(N node);
55  
56    /**
57     * Add {@code node} as a predecessor to the origin node. In the case of an undirected graph, it
58     * also becomes a successor. Associates {@code value} with the edge connecting the two nodes.
59     */
60    void addPredecessor(N node, V value);
61  
62    /**
63     * Add {@code node} as a successor to the origin node. In the case of an undirected graph, it also
64     * becomes a predecessor. Associates {@code value} with the edge connecting the two nodes. Returns
65     * the value previously associated with the edge connecting the two nodes.
66     */
67    @CanIgnoreReturnValue
68    V addSuccessor(N node, V value);
69  }