/** * Returns the set of edges incident to <code>v</code> that should be * tested. By default, this is the set of outgoing edges for instances of * <code>Graph</code>, the set of incident edges for instances of * <code>Hypergraph</code>, and is otherwise undefined. */ protected Collection<E> getEdgesToCheck(V v) { if (g instanceof Graph) { return ((Graph<V, E>) g).getOutEdges(v); } return g.getIncidentEdges(v); }
/** * @param v the vertex to test * @return <code>true</code> if {@code v} has no parent */ public boolean isRoot(V v) { if (!delegate.containsVertex(v)) return false; return getParent(v) == null; }
/** * @param v the vertex to test * @return <code>true</code> if <code>v</code> is neither * a leaf nor the root of this tree */ public boolean isInternal(V v) { if (!delegate.containsVertex(v)) return false; return isLeaf(v) == false && isRoot(v) == false; }
private static Hypergraph<ElementName, Integer> makeNonDirectional( final DirectedGraph<ElementName, Integer> packageNameGraph) { final SparseMultigraph<ElementName, Integer> g = new SparseMultigraph<ElementName, Integer>(); int i = 0; for (final ElementName each : packageNameGraph.getVertices()) { g.addVertex(each); for (final ElementName s : packageNameGraph.getSuccessors(each)) { g.addEdge(i, each, s); i++; } } return g; }
/** * @see edu.uci.ics.jung.graph.Graph#addEdge(java.lang.Object, * java.lang.Object, java.lang.Object) */ @Override public boolean addEdge(E e, V v1, V v2) { return delegate.addEdge(e, v1, v2); }
/** * @see edu.uci.ics.jung.graph.Graph#getOutEdges(java.lang.Object) */ @Override public Collection<E> getOutEdges(V vertex) { return delegate.getOutEdges(vertex); }
@Override public Tree<V, E> create() { return new DelegateTree<V, E>( new DirectedSparseMultigraph<V, E>()); } };
@Override public int getIncidentCount(E edge) { if (!delegate.containsEdge(edge)) { return 0; } // all edges in a tree connect exactly 2 vertices return 2; }
@Override public DirectedSparseMultigraph<V, E> newInstance() { return new DirectedSparseMultigraph<V, E>(); } }
/** * Returns a {@link TreeBuilder} initialized with all properties queryable from {@code tree}. * * <p>The "queryable" properties are those that are exposed through the {@link CTree} interface, * such as {@link CTree#nodeOrder()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> TreeBuilder<N> from(CTree<N> tree) { return new TreeBuilder<Object>().nodeOrder(tree.nodeOrder()); }
/** * Adds {@code edge} to this graph with the specified {@code endpoints}, * with the default edge type. * * @return {@code} true iff the graph was modified as a result of this call */ public boolean addEdge(E edge, Pair<? extends V> endpoints) { return addEdge(edge, endpoints, this.getDefaultEdgeType()); }
/** * Returns a {@link TreeNetworkBuilder} initialized with all properties queryable from {@code * tree}. * * <p>The "queryable" properties are those that are exposed through the {@link CTree} interface, * such as {@link CTree#nodeOrder()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N, E> TreeNetworkBuilder<N, E> from(CTreeNetwork<N, E> tree) { return new TreeNetworkBuilder<N, E>().nodeOrder(tree.nodeOrder()); }
@Override public Graph<V, E> newInstance() { return delegate.newInstance(); } }
private static Hypergraph<ElementName, Integer> makeNonDirectional( final DirectedGraph<ElementName, Integer> packageNameGraph) { final SparseMultigraph<ElementName, Integer> g = new SparseMultigraph<ElementName, Integer>(); int i = 0; for (final ElementName each : packageNameGraph.getVertices()) { g.addVertex(each); for (final ElementName s : packageNameGraph.getSuccessors(each)) { g.addEdge(i, each, s); i++; } } return g; }
/** * Returns the set of edges incident to <code>v</code> that should be tested. * By default, this is the set of outgoing edges for instances of <code>Graph</code>, * the set of incident edges for instances of <code>Hypergraph</code>, * and is otherwise undefined. */ protected Collection<E> getEdgesToCheck(V v) { if (g instanceof Graph) return ((Graph<V,E>)g).getOutEdges(v); else return g.getIncidentEdges(v); }
/** * Returns <code>true</code> if <code>v</code> is neither a leaf nor the * root of this tree. * * @return <code>true</code> if <code>v</code> is neither a leaf nor the * root of this tree */ public boolean isInternal(V v) { if (!delegate.containsVertex(v)) { return false; } return isLeaf(v) == false && isRoot(v) == false; }
/** * computes whether the passed node is a root node (has no children) */ public boolean isRoot(V v) { if (!delegate.containsVertex(v)) { return false; } return getParent(v) == null; }
public Tree<V,E> get() { return new DelegateTree<V,E>(new DirectedSparseMultigraph<V,E>()); } };
/** * @see edu.uci.ics.jung.graph.Hypergraph#containsEdge(java.lang.Object) */ @Override public boolean containsEdge(E edge) { return delegate.containsEdge(edge); }