• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 javax.annotation.CheckForNull;
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 @ElementTypesAreNonnullByDefault
33 interface GraphConnections<N, V> {
34 
adjacentNodes()35   Set<N> adjacentNodes();
36 
predecessors()37   Set<N> predecessors();
38 
successors()39   Set<N> successors();
40 
41   /**
42    * Returns an iterator over the incident edges.
43    *
44    * @param thisNode The node that this all of the connections in this class are connected to.
45    */
incidentEdgeIterator(N thisNode)46   Iterator<EndpointPair<N>> incidentEdgeIterator(N thisNode);
47 
48   /**
49    * Returns the value associated with the edge connecting the origin node to {@code node}, or null
50    * if there is no such edge.
51    */
52   @CheckForNull
value(N node)53   V value(N node);
54 
55   /** Remove {@code node} from the set of predecessors. */
removePredecessor(N node)56   void removePredecessor(N node);
57 
58   /**
59    * Remove {@code node} from the set of successors. Returns the value previously associated with
60    * the edge connecting the two nodes.
61    */
62   @CanIgnoreReturnValue
63   @CheckForNull
removeSuccessor(N node)64   V removeSuccessor(N node);
65 
66   /**
67    * Add {@code node} as a predecessor to the origin node. In the case of an undirected graph, it
68    * also becomes a successor. Associates {@code value} with the edge connecting the two nodes.
69    */
addPredecessor(N node, V value)70   void addPredecessor(N node, V value);
71 
72   /**
73    * Add {@code node} as a successor to the origin node. In the case of an undirected graph, it also
74    * becomes a predecessor. Associates {@code value} with the edge connecting the two nodes. Returns
75    * the value previously associated with the edge connecting the two nodes.
76    */
77   @CanIgnoreReturnValue
78   @CheckForNull
addSuccessor(N node, V value)79   V addSuccessor(N node, V value);
80 }
81