GraphUtil { public static <V extends IVertex, E extends IEdge<V>> int getDegree (IGraph<V, E> graph, V vertex, EDegree mode) { int nDegree = 0; for (E edge : graph.getEdges ()) if ((mode.isInDegree () && edge.getHeadVertex ().equals (vertex)) || (mode.isOutDegree () && edge.getTailVertex ().equals (vertex))) nDegree++; return nDegree; }  static Collection<V> getRootVertices(IGraph<V, E> graph); static Collection<V> getLeafVertices(IGraph<V, E> graph); static Collection<V> getSuccessors(IGraph<V, E> graph, V vertex); static Collection<V> getPredecessors(IGraph<V, E> graph, V vertex); static Collection<V> getNeighbors(IGraph<V, E> graph, V vertex); static int getDegree(IGraph<V, E> graph, V vertex, EDegree mode); static Iterable<VertexWithDegree<V, E>> getVerticesWithDegree(IGraph<V, E> graph, EDegree mode); static Iterable<V> getVerticesSortedByDegree(IGraph<V, E> graph, EDegree mode, boolean bSortAscending); static IVertex[] getTopologicalSort(IGraph<V, E> graph); static boolean isTopologicalOrder(IGraph<V, E> graph, Iterable<V> listVertices);  }
@Test public void testGetDegree () { assertEquals (0, GraphUtil.getDegree (m_graph, m_vA, GraphUtil.EDegree.IN_DEGREE)); assertEquals (3, GraphUtil.getDegree (m_graph, m_vA, GraphUtil.EDegree.OUT_DEGREE)); assertEquals (3, GraphUtil.getDegree (m_graph, m_vA, GraphUtil.EDegree.INOUT_DEGREE)); assertEquals (2, GraphUtil.getDegree (m_graph, m_vB, GraphUtil.EDegree.IN_DEGREE)); assertEquals (1, GraphUtil.getDegree (m_graph, m_vB, GraphUtil.EDegree.OUT_DEGREE)); assertEquals (3, GraphUtil.getDegree (m_graph, m_vB, GraphUtil.EDegree.INOUT_DEGREE)); assertEquals (1, GraphUtil.getDegree (m_graph, m_vC, GraphUtil.EDegree.IN_DEGREE)); assertEquals (2, GraphUtil.getDegree (m_graph, m_vC, GraphUtil.EDegree.OUT_DEGREE)); assertEquals (3, GraphUtil.getDegree (m_graph, m_vC, GraphUtil.EDegree.INOUT_DEGREE)); assertEquals (1, GraphUtil.getDegree (m_graph, m_vD, GraphUtil.EDegree.IN_DEGREE)); assertEquals (1, GraphUtil.getDegree (m_graph, m_vD, GraphUtil.EDegree.OUT_DEGREE)); assertEquals (2, GraphUtil.getDegree (m_graph, m_vD, GraphUtil.EDegree.INOUT_DEGREE)); assertEquals (2, GraphUtil.getDegree (m_graph, m_vE, GraphUtil.EDegree.IN_DEGREE)); assertEquals (1, GraphUtil.getDegree (m_graph, m_vE, GraphUtil.EDegree.OUT_DEGREE)); assertEquals (3, GraphUtil.getDegree (m_graph, m_vE, GraphUtil.EDegree.INOUT_DEGREE)); assertEquals (2, GraphUtil.getDegree (m_graph, m_vF, GraphUtil.EDegree.IN_DEGREE)); assertEquals (0, GraphUtil.getDegree (m_graph, m_vF, GraphUtil.EDegree.OUT_DEGREE)); assertEquals (2, GraphUtil.getDegree (m_graph, m_vF, GraphUtil.EDegree.INOUT_DEGREE)); }