| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Graph |
|
| 1.0;1 |
| 1 | /* | |
| 2 | ||
| 3 | dsh-graph Directed graph interface and implementation. | |
| 4 | Copyright (c) 2004-2013 held jointly by the individual authors. | |
| 5 | ||
| 6 | This library is free software; you can redistribute it and/or modify it | |
| 7 | under the terms of the GNU Lesser General Public License as published | |
| 8 | by the Free Software Foundation; either version 3 of the License, or (at | |
| 9 | your option) any later version. | |
| 10 | ||
| 11 | This library is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or | |
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | |
| 14 | License for more details. | |
| 15 | ||
| 16 | You should have received a copy of the GNU Lesser General Public License | |
| 17 | along with this library; if not, write to the Free Software Foundation, | |
| 18 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 19 | ||
| 20 | > http://www.fsf.org/licensing/licenses/lgpl.html | |
| 21 | > http://www.opensource.org/licenses/lgpl-license.php | |
| 22 | ||
| 23 | */ | |
| 24 | package org.dishevelled.graph; | |
| 25 | ||
| 26 | import java.util.Collection; | |
| 27 | import java.util.Map; | |
| 28 | import java.util.Set; | |
| 29 | ||
| 30 | import org.dishevelled.functor.UnaryPredicate; | |
| 31 | import org.dishevelled.functor.UnaryProcedure; | |
| 32 | ||
| 33 | /** | |
| 34 | * Directed graph with typed values on nodes and edges. | |
| 35 | * | |
| 36 | * @param <N> node value type | |
| 37 | * @param <E> edge value type | |
| 38 | * @author Michael Heuer | |
| 39 | * @version $Revision$ $Date$ | |
| 40 | */ | |
| 41 | public interface Graph<N, E> | |
| 42 | { | |
| 43 | ||
| 44 | /** | |
| 45 | * Return true if this graph is empty. | |
| 46 | * | |
| 47 | * @return true if this graph is empty | |
| 48 | */ | |
| 49 | boolean isEmpty(); | |
| 50 | ||
| 51 | /** | |
| 52 | * Return the number of nodes in this graph. | |
| 53 | * | |
| 54 | * @return the number of nodes in this graph | |
| 55 | */ | |
| 56 | int nodeCount(); | |
| 57 | ||
| 58 | /** | |
| 59 | * Return a read-only set view of the nodes in this graph. The view | |
| 60 | * may be empty (if <code>nodeCount() == 0</code>) but will not be null. | |
| 61 | * | |
| 62 | * @return a read-only set view of the nodes in this graph | |
| 63 | */ | |
| 64 | Set<Node<N, E>> nodes(); | |
| 65 | ||
| 66 | /** | |
| 67 | * Return a read-only collection view of the node values in this graph. The | |
| 68 | * view may be empty (if <code>nodeCount() == 0</code>) but will not be null. | |
| 69 | * | |
| 70 | * @return a read-only collection view of the node values in this graph | |
| 71 | */ | |
| 72 | Collection<N> nodeValues(); | |
| 73 | ||
| 74 | /** | |
| 75 | * Return a map of type <code><Node<N, E>, T></code> with | |
| 76 | * the nodes in this graph as keys. The keys in the returned map | |
| 77 | * reference the nodes in this graph and are read-only. Each key maps to | |
| 78 | * the specified default value, which may be null. The map may be empty | |
| 79 | * (if <code>nodeCount() == 0</code>) but will not be null. | |
| 80 | * | |
| 81 | * @param <T> node map value type | |
| 82 | * @param defaultValue default value for each node mapping | |
| 83 | * @return a map of type <code><Node<N, E>, T></code> with | |
| 84 | * the nodes in this graph as keys | |
| 85 | */ | |
| 86 | <T> Map<Node<N, E>, T> nodeMap(T defaultValue); | |
| 87 | ||
| 88 | /** | |
| 89 | * Apply the specified procedure to each node in this graph. | |
| 90 | * | |
| 91 | * @param procedure procedure to apply, must not be null | |
| 92 | */ | |
| 93 | void forEachNode(UnaryProcedure<Node<N, E>> procedure); | |
| 94 | ||
| 95 | /** | |
| 96 | * Apply the specified procedure to each node in this graph | |
| 97 | * accepted by the specified predicate. | |
| 98 | * | |
| 99 | * @param predicate node predicate, must not be null | |
| 100 | * @param procedure procedure to apply, must not be null | |
| 101 | */ | |
| 102 | void forEachNode(UnaryPredicate<Node<N, E>> predicate, | |
| 103 | UnaryProcedure<Node<N, E>> procedure); | |
| 104 | ||
| 105 | /** | |
| 106 | * Apply the specified procedure to each node value in this graph. | |
| 107 | * | |
| 108 | * @param procedure procedure to apply, must not be null | |
| 109 | */ | |
| 110 | void forEachNodeValue(UnaryProcedure<? super N> procedure); | |
| 111 | ||
| 112 | /** | |
| 113 | * Apply the specified procedure to each node value in this graph | |
| 114 | * accepted by the specified predicate. | |
| 115 | * | |
| 116 | * @param predicate node value predicate, must not be null | |
| 117 | * @param procedure procedure to apply, must not be null | |
| 118 | */ | |
| 119 | void forEachNodeValue(UnaryPredicate<N> predicate, UnaryProcedure<N> procedure); | |
| 120 | ||
| 121 | /** | |
| 122 | * Return the number of edges in this graph. | |
| 123 | * | |
| 124 | * @return the number of edges in this graph | |
| 125 | */ | |
| 126 | int edgeCount(); | |
| 127 | ||
| 128 | /** | |
| 129 | * Return a read-only set view of the edges in this graph. The view | |
| 130 | * may be empty (if <code>edgeCount() == 0</code>) but will not be null. | |
| 131 | * | |
| 132 | * @return a read-only set view of the edges in this graph | |
| 133 | */ | |
| 134 | Set<Edge<N, E>> edges(); | |
| 135 | ||
| 136 | /** | |
| 137 | * Return a read-only collection view of the edge values in this graph. The | |
| 138 | * view may be empty (if <code>edgeCount() == 0</code>) but will not be null. | |
| 139 | * | |
| 140 | * @return a read-only collection view of the edge values in this graph | |
| 141 | */ | |
| 142 | Collection<E> edgeValues(); | |
| 143 | ||
| 144 | /** | |
| 145 | * Return a map of type <code><Edge<N, E>, T></code> with | |
| 146 | * the edges in this graph as keys. The keys in the returned map | |
| 147 | * reference the edges in this graph and are read-only. Each key maps to | |
| 148 | * the specified default value, which may be null. The map may be empty | |
| 149 | * (if <code>edgeCount() == 0</code>) but will not be null. | |
| 150 | * | |
| 151 | * @param <T> edge map value type | |
| 152 | * @param defaultValue default value for each edge mapping | |
| 153 | * @return a map of type <code><Edge<N, E>, T></code> with | |
| 154 | * the edges in this graph as keys | |
| 155 | */ | |
| 156 | <T> Map<Edge<N, E>, T> edgeMap(T defaultValue); | |
| 157 | ||
| 158 | /** | |
| 159 | * Apply the specified procedure to each edge in this graph. | |
| 160 | * | |
| 161 | * @param procedure procedure to apply, must not be null | |
| 162 | */ | |
| 163 | void forEachEdge(UnaryProcedure<Edge<N, E>> procedure); | |
| 164 | ||
| 165 | /** | |
| 166 | * Apply the specified procedure to each edge in this graph | |
| 167 | * accepted by the specified predicate. | |
| 168 | * | |
| 169 | * @param predicate edge predicate, must not be null | |
| 170 | * @param procedure procedure to apply, must not be null | |
| 171 | */ | |
| 172 | void forEachEdge(UnaryPredicate<Edge<N, E>> predicate, | |
| 173 | UnaryProcedure<Edge<N, E>> procedure); | |
| 174 | ||
| 175 | /** | |
| 176 | * Apply the specified procedure to each edge value in this graph. | |
| 177 | * | |
| 178 | * @param procedure procedure to apply, must not be null | |
| 179 | */ | |
| 180 | void forEachEdgeValue(UnaryProcedure<? super E> procedure); | |
| 181 | ||
| 182 | /** | |
| 183 | * Apply the specified procedure to each edge value in this graph | |
| 184 | * accepted by the specified predicate. | |
| 185 | * | |
| 186 | * @param predicate edge value predicate, must not be null | |
| 187 | * @param procedure procedure to apply, must not be null | |
| 188 | */ | |
| 189 | void forEachEdgeValue(UnaryPredicate<E> predicate, UnaryProcedure<E> procedure); | |
| 190 | ||
| 191 | /** | |
| 192 | * Clear the nodes and edges in this graph (optional operation). | |
| 193 | * | |
| 194 | * @throws UnsupportedOperationException if the <code>clear</code> | |
| 195 | * operation is not supported by this graph | |
| 196 | */ | |
| 197 | void clear(); | |
| 198 | ||
| 199 | /** | |
| 200 | * Create and return a new node in this graph with the specified value (optional operation). | |
| 201 | * | |
| 202 | * @param value value | |
| 203 | * @return a new node in this graph with the specified value | |
| 204 | * @throws UnsupportedOperationException if the <code>createNode</code> | |
| 205 | * operation is not supported by this graph | |
| 206 | */ | |
| 207 | Node<N, E> createNode(N value); | |
| 208 | ||
| 209 | /** | |
| 210 | * Remove the specified node and any edges connecting the | |
| 211 | * node from this graph (optional operation). | |
| 212 | * | |
| 213 | * @param node node to remove, must not be null and must be | |
| 214 | * contained in this graph | |
| 215 | * @throws UnsupportedOperationException if the <code>remove(Node)</code> | |
| 216 | * operation is not supported by this graph | |
| 217 | */ | |
| 218 | void remove(Node<N, E> node); | |
| 219 | ||
| 220 | /** | |
| 221 | * Create and return a new edge in this graph with the specified value | |
| 222 | * connecting the specified source and target nodes (optional operation). | |
| 223 | * | |
| 224 | * @param value value | |
| 225 | * @param source source node, must not be null and must be | |
| 226 | * contained in this graph | |
| 227 | * @param target target node, must not be null and must be | |
| 228 | * contained in this graph | |
| 229 | * @return a new edge in this graph with the specified value | |
| 230 | * connecting the specified source and target nodes | |
| 231 | * @throws UnsupportedOperationException if the <code>createEdge</code> | |
| 232 | * operation is not supported by this graph | |
| 233 | */ | |
| 234 | Edge<N, E> createEdge(Node<N, E> source, Node<N, E> target, E value); | |
| 235 | ||
| 236 | /** | |
| 237 | * Remove the specified edge from this graph (optional operation). | |
| 238 | * | |
| 239 | * @param edge edge to remove, must not be null and must be | |
| 240 | * contained in this graph | |
| 241 | * @throws UnsupportedOperationException if the <code>remove(Edge)</code> | |
| 242 | * operation is not supported by this graph | |
| 243 | */ | |
| 244 | void remove(Edge<N, E> edge); | |
| 245 | } |