/** * Adds an <code>Application</code> or a <code>Library</code> to the <code>Project</code>. * * @param builder An instance of the <code>Application</code> or a <code>Library</code> class. */ public void addBuilder(Builder builder) { String name = Integer.toString(builder.hashCode()); dependencies.put(name, builder); if (!dependencies.containsVertex(name)) { dependencies.addVertex(new Vertex<String, Builder>(name)); } }
/** * Instructs the <code>Project</code> that one <code>Builder</code> depends on the other. Both * <code>Builder</code> instances must first be added to this <code>Project</code>. * * <p><code>builder1</code> depends on <code>builder2</code>. * * @param builder1 A <code>Builder</code>. This <code>Builder</code> depends on the other. * @param builder2 A <code>Builder</code>. */ public void dependsOn(Builder builder1, Builder builder2) { String head = Integer.toString(builder1.hashCode()), tail = Integer.toString(builder2.hashCode()); if (!head.equals(tail) && dependencies.containsKey(head) && dependencies.containsKey(tail) && !dependencies.dependencyExists(head, tail)) { dependencies.addDependency(head, tail); } }
/** * Gets the build order for the <code>Project</code>. The build order is determined by the * dependencies among <code>Builder</code> instances. * * @return <code>Iterator</code> build order; the elements are either instance of the <code> * Application</code> class or the <code>Library</code> class. */ public Iterator<Builder> getBuildOrder() { final List<Builder> buildOrder = new ArrayList<Builder>(dependencies.size()); Algorithms.topologicalSort( dependencies, new Visitor<Vertex<String, Builder>>() { public void visit(Vertex<String, Builder> v) { String name = v.getWeight(); buildOrder.add(dependencies.get(name)); } }); return buildOrder.iterator(); }
/** * Removes an <code>Application</code> or a <code>Library</code> from the <code>Project</code>. * * @param builder An instance of the <code>Application</code> or a <code>Library</code> class. */ public void removeBuilder(Builder builder) { String name = Integer.toString(builder.hashCode()); dependencies.remove(name); dependencies.removeVertex(name); }