@Override public Collection<V> getChildren(V vertex) { return ((Forest<V, E>) delegate).getChildren(vertex); }
@Override public Collection<V> getChildren(V vertex) { return ((Forest<V, E>) delegate).getChildren(vertex); }
public Collection<V> getChildren(V vertex) { return ((Forest<V,E>)delegate).getChildren(vertex); }
public Collection<V> getChildren(V vertex) { return ((Forest<V,E>)delegate).getChildren(vertex); }
public List<V> getChildren(V parentNode) { Collection<V> children = graph.getChildren(parentNode); List<V> result = new ArrayList<V>(); if (children != null) { result.addAll(children); } return result; }
public List<V> getChildren(V parentNode) { Collection<V> children = graph.getChildren(parentNode); List<V> result = new ArrayList<V>(); if (children != null) { result.addAll(children); } return result; }
/** * Get all the nodes which are below the {@code parentNode},that is children, children's children etc. The returned * list includes the {@code parentNode} * * @param parentNode * @return */ public List<V> getSubtreeNodes(V parentNode) { Collection<V> children = graph.getChildren(parentNode); List<V> list = new ArrayList<V>(); list.add(parentNode); if (children != null) { for (V v : children) { list.addAll(getSubtreeNodes(v)); } } return list; }
/** * Get all the nodes which are below the {@code parentNode},that is children, children's children etc. The returned * list includes the {@code parentNode} * * @param parentNode * @return */ public List<V> getSubtreeNodes(V parentNode) { Collection<V> children = graph.getChildren(parentNode); List<V> list = new ArrayList<V>(); list.add(parentNode); if (children != null) { for (V v : children) { list.addAll(getSubtreeNodes(v)); } } return list; }
/** * Finds all the leaves for the specified {@code parentNode}, that is, all those with no children; * * @param parentNode * @param leaves */ private void findLeaves(V parentNode, List<V> leaves) { if (leaves == null) { return; } Collection<V> children = graph.getChildren(parentNode); if (children == null) { return; } if (children.isEmpty()) { leaves.add(parentNode); } else { for (V v : children) { findLeaves(v, leaves); } } }
/** * Finds all the leaves for the specified {@code parentNode}, that is, all those with no children; * * @param parentNode * @param leaves */ private void findLeaves(V parentNode, List<V> leaves) { if (leaves == null) { return; } Collection<V> children = graph.getChildren(parentNode); if (children == null) { return; } if (children.isEmpty()) { leaves.add(parentNode); } else { for (V v : children) { findLeaves(v, leaves); } } }
protected void setPolars(List<V> kids, Point2D parentLocation, double parentRadius) { int childCount = kids.size(); if(childCount == 0) return; // handle the 1-child case with 0 limit on angle. double angle = Math.max(0, Math.PI / 2 * (1 - 2.0/childCount)); double childRadius = parentRadius*Math.cos(angle) / (1 + Math.cos(angle)); double radius = parentRadius - childRadius; double rand = Math.random(); for(int i=0; i< childCount; i++) { V child = kids.get(i); double theta = i* 2*Math.PI/childCount + rand; radii.put(child, childRadius); PolarPoint pp = new PolarPoint(theta, radius); polarLocations.put(child, pp); Point2D p = PolarPoint.polarToCartesian(pp); p.setLocation(p.getX()+parentLocation.getX(), p.getY()+parentLocation.getY()); locations.put(child, p); setPolars(new ArrayList<V>(graph.getChildren(child)), p, childRadius); } }
protected void setPolars(List<V> kids, Point2D parentLocation, double parentRadius) { int childCount = kids.size(); if(childCount == 0) return; // handle the 1-child case with 0 limit on angle. double angle = Math.max(0, Math.PI / 2 * (1 - 2.0/childCount)); double childRadius = parentRadius*Math.cos(angle) / (1 + Math.cos(angle)); double radius = parentRadius - childRadius; double rand = Math.random(); for(int i=0; i< childCount; i++) { V child = kids.get(i); double theta = i* 2*Math.PI/childCount + rand; radii.put(child, childRadius); PolarPoint pp = new PolarPoint(theta, radius); polarLocations.put(child, pp); Point2D p = PolarPoint.polarToCartesian(pp); p.setLocation(p.getX()+parentLocation.getX(), p.getY()+parentLocation.getY()); locations.put(child, p); setPolars(new ArrayList<V>(graph.getChildren(child)), p, childRadius); } }
protected void setRootPolars() { List<V> roots = TreeUtils.getRoots(graph); if(roots.size() == 1) { // its a Tree V root = roots.get(0); setRootPolar(root); setPolars(new ArrayList<V>(graph.getChildren(root)), getCenter(), getSize().width/2); } else if (roots.size() > 1) { // its a Forest setPolars(roots, getCenter(), getSize().width/2); } }
protected void setRootPolars() { List<V> roots = TreeUtils.getRoots(graph); if(roots.size() == 1) { // its a Tree V root = roots.get(0); setRootPolar(root); setPolars(new ArrayList<V>(graph.getChildren(root)), getCenter(), getSize().width/2); } else if (roots.size() > 1) { // its a Forest setPolars(roots, getCenter(), getSize().width/2); } }