@Override public void describe(DAGNode<Component, Dependency> node, DescriptionWriter description) { node.getLabel().getSatisfaction().visit(new LabelDescriptionVisitor(description)); description.putField("cachePolicy", node.getLabel().getCachePolicy().name()); List<DAGNode<Component, Dependency>> edges = node.getOutgoingEdges() .stream() .sorted(GraphtUtils.DEP_EDGE_ORDER) .map(DAGEdge::getTail) .collect(Collectors.toList()); description.putList("dependencies", edges, INSTANCE); } }
/** * Set the default cache policy used by injectors created by this builder. * * @param policy The default policy * @return This builder * @throws NullPointerException if policy is null * @throws IllegalArgumentException if policy is NO_PREFERENCE */ public InjectorBuilder setDefaultCachePolicy(CachePolicy policy) { if (policy.equals(CachePolicy.NO_PREFERENCE)) { throw new IllegalArgumentException("Cannot be NO_PREFERENCE"); } cachePolicy = policy; return this; }
builder.setCachePolicy(CachePolicy.valueOf(policy));
@Override public void describe(DAGNode<Component, Dependency> node, DescriptionWriter description) { node.getLabel().getSatisfaction().visit(new LabelDescriptionVisitor(description)); description.putField("cachePolicy", node.getLabel().getCachePolicy().name()); List<DAGNode<Component, Dependency>> edges = Lists.transform(GraphtUtils.DEP_EDGE_ORDER.sortedCopy(node.getOutgoingEdges()), DAGEdge.<Component,Dependency>extractTail()); description.putList("dependencies", edges, INSTANCE); } }
/** * <p> * Create a new DefaultInjector. <tt>maxDepth</tt> represents the maximum * depth of the dependency hierarchy before it is assume that there is a * cycle. Bindings with a NO_PREFERENCE cache policy will use * <tt>defaultPolicy</tt>. * <p> * This constructor can be used to increase this depth in the event that * configuration requires it, although for most purposes the default 100 * should be sufficient. * * @param defaultPolicy The CachePolicy used in place of NO_PREFERENCE * @param maxDepth The maximum depth of the dependency hierarchy * @param functions The BindingFunctions to use, ordered with highest * priority functions first * @throws IllegalArgumentException if maxDepth is less than 1, or if * defaultPolicy is NO_PREFERENCE * @throws NullPointerException if spi or functions are null */ public DefaultInjector(CachePolicy defaultPolicy, int maxDepth, BindingFunction... functions) { if (defaultPolicy.equals(CachePolicy.NO_PREFERENCE)) { throw new IllegalArgumentException("Default CachePolicy cannot be NO_PREFERENCE"); } solver = DependencySolver.newBuilder() .addBindingFunctions(functions) .setMaxDepth(maxDepth) .build(); instantiator = InjectionContainer.create(defaultPolicy); }