Returns true iff graph1 and graph2 have the same node connections. Note: Network instances can only be equal to other Network instances. In particular, Graphs that are not also Networks cannot be equal to Networks. @see Network#equals(Obje
(@Nullable Graph<?> graph1, @Nullable Graph<?> graph2)
| 278 | |
| 279 | |
| 280 | public static boolean equal(@Nullable Graph<?> graph1, @Nullable Graph<?> graph2) { |
| 281 | // If both graphs are Network instances, use equal(Network, Network) instead |
| 282 | if (graph1 instanceof Network && graph2 instanceof Network) { |
| 283 | return equal((Network<?, ?>) graph1, (Network<?, ?>) graph2); |
| 284 | } |
| 285 | |
| 286 | // Otherwise, if either graph is a Network (but not both), they can't be equal. |
| 287 | if (graph1 instanceof Network || graph2 instanceof Network) { |
| 288 | return false; |
| 289 | } |
| 290 | if (graph1 == graph2) { |
| 291 | return true; |
| 292 | } |
| 293 | if (graph1 == null || graph2 == null) { |
| 294 | return false; |
| 295 | } |
| 296 | if (!graph1.nodes().equals(graph2.nodes())) { |
| 297 | return false; |
| 298 | } |
| 299 | for (Object node : graph1.nodes()) { |
| 300 | if (!graph1.successors(node).equals(graph2.successors(node))) { |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | boolean bothUndirected = !graph1.isDirected() && !graph2.isDirected(); |
| 305 | if (!bothUndirected |
| 306 | && !graph1.predecessors(node).equals(graph2.predecessors(node))) { |
| 307 | return false; |
| 308 | } |
| 309 | } |
| 310 | return true; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Returns true iff {@code graph1} and {@code graph2} have the same node/edge relationships. |
no test coverage detected