package jrummikub.ai.fdsolver.constraint; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; import jrummikub.ai.fdsolver.Propagator; import jrummikub.ai.fdsolver.Var; public class ComparatorPropagator implements Propagator { private Var x, y; private Comparator comparator; private boolean allowEqual; public ComparatorPropagator(Comparator comparator, boolean allowEqual, Var x, Var y) { this.comparator = comparator; this.allowEqual = allowEqual; this.x = x; this.y = y; } @Override public Collection> getWatchedVars() { return Arrays.>asList(y); } @Override public void propagate() { T maxY = Collections.max(y.getRange(), comparator); for(Iterator i = x.iterator(); i.hasNext();) { T value = i.next(); int comparision = comparator.compare(value, maxY); if (comparision > 0 || comparision == 0 && !allowEqual) { i.remove(); } } } }