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