public boolean containsNode(V node) { return graph.containsVertex(node); }
public boolean containsNode(V node) { return graph.containsVertex(node); }
@Override public synchronized boolean addService(@Nonnull T service) { checkNotNull(service); log.debug("adding service"); if (graph.containsVertex(service)) { return false; } return graph.addVertex(service); }
/** * Connects <code>subTree</code> to <code>tree</code> by attaching it as a child * of <code>node</code> with edge <code>connectingEdge</code>. * @param <V> the vertex type * @param <E> the edge type * @param tree the tree to which <code>subTree</code> is to be added * @param subTree the tree which is to be grafted on to <code>tree</code> * @param node the parent of <code>subTree</code> in its new position in <code>tree</code> * @param connectingEdge the edge used to connect <code>subtree</code>'s root as a child of <code>node</code> */ public static <V,E> void addSubTree(Forest<V,E> tree, Forest<V,E> subTree, V node, E connectingEdge) { if (node != null && !tree.containsVertex(node)) throw new IllegalArgumentException("Specified tree does not contain the specified node as a vertex"); V root = subTree.getTrees().iterator().next().getRoot(); addFromSubTree(tree, subTree, connectingEdge, node, root); }
/** * Returns the subtree of <code>tree</code> which is rooted at <code>root</code> as a <code>Forest</code>. * The tree returned is an independent entity, although it uses the same vertex and edge objects. * @param <V> the vertex type * @param <E> the edge type * @param forest the tree whose subtree is to be extracted * @param root the root of the subtree to be extracted * @return the subtree of <code>tree</code> which is rooted at <code>root</code> * @throws InstantiationException if a new tree of the same type cannot be created * @throws IllegalAccessException if a new tree of the same type cannot be created */ @SuppressWarnings("unchecked") public static <V,E> Tree<V,E> getSubTree(Forest<V,E> forest, V root) throws InstantiationException, IllegalAccessException { if (!forest.containsVertex(root)) throw new IllegalArgumentException("Specified tree does not contain the specified root as a vertex"); Forest<V,E> subforest = forest.getClass().newInstance(); subforest.addVertex(root); growSubTree(forest, subforest, root); return subforest.getTrees().iterator().next(); }
/** * Connects <code>subTree</code> to <code>tree</code> by attaching it as a * child of <code>node</code> with edge <code>connectingEdge</code>. * * @param <V> * the vertex type * @param <E> * the edge type * @param tree * the tree to which <code>subTree</code> is to be added * @param subTree * the tree which is to be grafted on to <code>tree</code> * @param node * the parent of <code>subTree</code> in its new position in * <code>tree</code> * @param connectingEdge * the edge used to connect <code>subtree</code>'s root as a * child of <code>node</code> */ public static <V, E> void addSubTree(Forest<V, E> tree, Forest<V, E> subTree, V node, E connectingEdge) { if (node != null && !tree.containsVertex(node)) { throw new IllegalArgumentException( "Specified tree does not contain the specified node as a vertex"); } V root = subTree.getTrees().iterator().next().getRoot(); addFromSubTree(tree, subTree, connectingEdge, node, root); }
@Override public synchronized void createDependency(@Nonnull T dependant, @Nonnull T dependency, @Nonnull Dependency.Type type) { checkNotNull(dependant); checkNotNull(dependency); checkNotNull(type); if (hasDependency(dependant, dependency)) { throw new DuplicateDependencyException("There can only be one dependency between the same two services"); } if (!graph.containsVertex(dependant)) { graph.addVertex(dependant); } if (!graph.containsVertex(dependency)) { graph.addVertex(dependency); } ServiceEdge edge = new ServiceEdge(type); graph.addEdge(edge, dependant, dependency); if (detectCycle(dependant, dependency)) { throw new CycleDetectedException("Creating dependency from " + dependant + " to " + dependency + " has caused a loop"); } }
/** * Returns the subtree of <code>tree</code> which is rooted at * <code>root</code> as a <code>Forest<V,E></code>. The tree returned is an * independent entity, although it uses the same vertex and edge objects. * * @param <V> * the vertex type * @param <E> * the edge type * @param forest * the tree whose subtree is to be extracted * @param root * the root of the subtree to be extracted * @return the subtree of <code>tree</code> which is rooted at * <code>root</code> * @throws InstantiationException * if a new tree of the same type cannot be created * @throws IllegalAccessException */ public static <V, E> Tree<V, E> getSubTree(Forest<V, E> forest, V root) { if (!forest.containsVertex(root)) { throw new IllegalArgumentException( "Specified tree does not contain the specified root as a vertex"); } Forest<V, E> subforest = (Forest<V, E>) forest.newInstance(); subforest.addVertex(root); growSubTree(forest, subforest, root); return subforest.getTrees().iterator().next(); }