@Override public void addNeighbor(final Node<T> n1, final Node<T> n2) { DependencyHandler<T> rh1, rh2; for (final Reaction<T> r1 : n1.getReactions()) { rh1 = hndlrs.get(r1); for (int j = 0; j < n2.getReactions().size(); j++) { final Reaction<T> r2 = n2.getReactions().get(j); if (mayInfluence(r2, r1) && influences(r2, r1.getInfluencingMolecules())) { rh2 = hndlrs.get(r2); if (!rh1.isInfluenced().contains(rh2)) { rh1.addInDependency(rh2); } if (!rh2.influences().contains(rh1)) { rh2.addOutDependency(rh1); } } if (mayInfluence(r1, r2) && influences(r1, r2.getInfluencingMolecules())) { rh2 = hndlrs.get(r2); if (!rh2.isInfluenced().contains(rh1)) { rh2.addInDependency(rh1); } if (!rh1.influences().contains(rh2)) { rh1.addOutDependency(rh2); } } } } }
private void createDependencies(final DependencyHandler<T> newHandler, final Reaction<T> newReaction) { /* * Will contain the reactions potentially influencing the new one */ final Iterable<Reaction<T>> inputCandidates = initCandidates(newReaction, newReaction.getInputContext()); /* * Will contain the reactions possibly influenced by the new one */ final Iterable<Reaction<T>> outputCandidates = initCandidates(newReaction, newReaction.getOutputContext()); /* * keySet() is not guaranteed to preserve the ordering. This can lead to * bad behaviors, since may change the order by which the reactions are * updated, and consequently ruin the predictability */ for (final Reaction<T> r : inputCandidates) { if (mayInfluence(r, newReaction) && influences(r, newReaction.getInfluencingMolecules())) { final DependencyHandler<T> dep = hndlrs.get(r); dep.addOutDependency(newHandler); newHandler.addInDependency(dep); } } for (final Reaction<T> r : outputCandidates) { if (mayInfluence(newReaction, r) && influences(newReaction, r.getInfluencingMolecules())) { final DependencyHandler<T> dep = hndlrs.get(r); newHandler.addOutDependency(dep); dep.addInDependency(newHandler); } } }