/** * Returns <code>true</code> if the passed node has no children. * * @return <code>true</code> if the passed node has no children */ public boolean isLeaf(V v) { if (!delegate.containsVertex(v)) { return false; } return getChildren(v).size() == 0; }
/** * get the number of children of the passed parent node */ public int getChildCount(V parent) { if (!delegate.containsVertex(parent)) return 0; return getChildren(parent).size(); }
/** * @param v the vertex to test * @return <code>true</code> if {@code v} has no children */ public boolean isLeaf(V v) { if (!delegate.containsVertex(v)) return false; return getChildren(v).size() == 0; }
/** * get the number of children of the passed parent node */ @Override public int getChildCount(V parent) { if (!delegate.containsVertex(parent)) { return 0; } return getChildren(parent).size(); }
public List<ClusterVO> getSiblings(Integer tenantId, ClusterVO cluster) { DelegateTree<ClusterVO, ItemAssocVO<Integer,Integer>> tree = clusters.get(tenantId); if (tree.isRoot(cluster)) return null; //root has no siblings ClusterVO parent = tree.getParent(cluster); Collection<ClusterVO> sibl = tree.getChildren(parent); List<ClusterVO> siblings = new ArrayList<ClusterVO>(); for (ClusterVO clusterVO : sibl) { if (!clusterVO.equals(cluster)) siblings.add(clusterVO); } return siblings; }
/** * remove the passed node, and all nodes that are descendants of the * passed node. * @param vertex the vertex to remove * @return <code>true</code> iff the tree was modified * @see edu.uci.ics.jung.graph.Graph#removeVertex(java.lang.Object) */ @Override public boolean removeVertex(V vertex) { if (!delegate.containsVertex(vertex)) return false; for(V v : getChildren(vertex)) { removeVertex(v); vertex_depths.remove(v); } // recalculate height vertex_depths.remove(vertex); return delegate.removeVertex(vertex); }
/** * remove the passed node, and all nodes that are descendants of the passed * node. * * @param vertex * @return <code>true</code> iff the tree was modified * @see edu.uci.ics.jung.graph.Graph#removeVertex(java.lang.Object) */ @Override public boolean removeVertex(V vertex) { if (!delegate.containsVertex(vertex)) { return false; } for (V v : getChildren(vertex)) { removeVertex(v); vertex_depths.remove(v); } // recalculate height vertex_depths.remove(vertex); return delegate.removeVertex(vertex); }
public void renameCluster(Integer tenantId, String clusterName, String newName) throws ClusterException { ClusterVO cluster = loadCluster(tenantId, idMappingDAO.lookup(clusterName), itemTypeDAO.getIdOfType(tenantId, ClusterService.ITEMTYPE_CLUSTER)); DelegateTree<ClusterVO, ItemAssocVO<Integer,Integer>> tree = clusters.get(tenantId); if (tree.isRoot(cluster)) throw new ClusterException("ROOT cluster cannot be renamed!"); ClusterVO parent = tree.getParent(cluster); ClusterVO newCluster = new ClusterVO(tenantId, idMappingDAO.lookup(newName), itemTypeDAO.getIdOfType(tenantId, ClusterService.ITEMTYPE_CLUSTER), newName, cluster.getDescription()); // add the new cluster addCluster(newCluster, parent); // move all children to the new cluster for (ClusterVO child : tree.getChildren(cluster)) { moveCluster(tenantId, child.getName(), newName); } if (logger.isDebugEnabled()) { logger.debug("removed all children: " + tree.isLeaf(cluster)); } // move all items to the new cluster for (ItemVO<Integer, Integer> item : getItemsOfCluster(cluster)) { addItemToCluster(newCluster, item); } // delete the old cluster removeCluster(tenantId, clusterName); }
private void removeClustersFromDB( DelegateTree<ClusterVO, ItemAssocVO<Integer,Integer>> tree, ClusterVO vertex) { List<ItemAssocVO<Integer,Integer>> edges = itemAssocService.getItemAssocsForItem(vertex.getItem().getTenant(), vertex.getItem(), null); //remove all edges in db for (ItemAssocVO<Integer,Integer> edge : edges) { itemAssocService.removeItemAssoc(edge.getId()); } profileDAO.deactivateProfile(vertex.getItem().getTenant(), vertex.getItem().getItem(), vertex.getItem().getType()); // remove all items from cluster for (ItemVO<Integer, Integer> item : getItemsOfCluster(vertex)) { try { removeItemFromCluster(vertex, item); } catch (ClusterException ce) { logger.error(ce.getMessage()); } } for (ClusterVO child : tree.getChildren(vertex)) { removeClustersFromDB(tree, child); } }