Skip to content

Commit

Permalink
Simplify injection context & improve solver comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Oct 3, 2013
1 parent 8798585 commit 50be480
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public class DependencySolver {
* @return The context from the initial injection.
*/
public static InjectionContext initialContext() {
return InjectionContext.singleton(ROOT_SATISFACTION.getSatisfaction(),
new AttributesImpl());
return InjectionContext.singleton(ROOT_SATISFACTION.getSatisfaction());
}

/**
Expand Down Expand Up @@ -244,9 +243,10 @@ private void replaceNode(DAGNode<CachedSatisfaction,DesireChain> old, DAGNode<Ca
*
* @param tree The unmerged tree to merge in.
* @param mergeTarget The graph to merge with.
* @param mergeRoot Whether to merge this with the root of the global graph. If {@code true},
* @param mergeRoot Whether to merge this with the root of the merge target. If {@code true},
* the outgoing edges of {@code tree} are added to the outgoing edges of
* the root of the global graph and the resulting graph returned.
* {@code mergeTarget} and the resulting graph is returned; otherwise, just the
* transformation of {@code tree} is returned.
* @return The new merged graph.
*/
private DAGNode<CachedSatisfaction,DesireChain> merge(DAGNode<CachedSatisfaction,DesireChain> tree,
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/grouplens/grapht/solver/InjectionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.grouplens.grapht.spi.Attributes;
import org.grouplens.grapht.spi.Satisfaction;
import org.grouplens.grapht.spi.reflect.AttributesImpl;
import org.grouplens.grapht.util.AbstractChain;

/**
Expand All @@ -36,11 +37,26 @@
*/
public class InjectionContext extends AbstractChain<Pair<Satisfaction,Attributes>> {
private static final long serialVersionUID = 1L;


/**
* Construct a singleton injection context.
* @param satisfaction The satisfaction.
* @param attrs The attributes.
* @return The injection context.
*/
public static InjectionContext singleton(Satisfaction satisfaction, Attributes attrs) {
return new InjectionContext(null, satisfaction, attrs);
}

/**
* Construct a singleton injection context with no attributes.
* @param satisfaction The satisfaction.
* @return The injection context.
*/
public static InjectionContext singleton(Satisfaction satisfaction) {
return singleton(satisfaction, new AttributesImpl());
}

private InjectionContext(InjectionContext prior, Satisfaction satisfaction, Attributes attrs) {
super(prior, Pair.of(satisfaction, attrs));
}
Expand Down

0 comments on commit 50be480

Please sign in to comment.