/** * Constructs a new set of bindings * * @param map a map of keys to values. The keys must be drawn from the set of query variables * @param vars the set of query variables referenced by these bindings */ public Bindings(final Map<String, T> map, final Query.QueryVariables vars) { this.map = map; int b = 0; for (String v : map.keySet()) { int i = vars.indexOf(v); b |= (1 << i); } boundVariables = b; }
/** * Finds whether these bindings are compatible with another set of bindings. Two sets of bindings * are compatible if, for each variable they have in common, they have identical values. * * @param other the other set of bindings to test * @param vars the query variables from which both sets of bindings are drawn * @return whether these bindings are compatible with the provided bindings */ public boolean compatibleWith(final Bindings<T> other, final Query.QueryVariables vars) { // compare only those bindings for variables shared between the two solutions int b = boundVariables & other.boundVariables; String[] a = vars.asArray(); for (String v : a) { if (0 != (b & 1)) { if (!map.get(v).equals(other.map.get(v))) { return false; } } b = b >> 1; } return true; }