public DimensionBinding combineWith(DimensionBinding other) {
        List<String> d1 = getDimensions();
        List<String> d2 = other.getDimensions();
        DimensionValues v1 = getValues();
        DimensionValues v2 = other.getValues();
        List<String> dimensions = new ArrayList<>();
        List<String> values = new ArrayList<>();
        int i1 = 0, i2 = 0;
        while (i1 < d1.size() && i2 < d2.size()) {
            if (d1.get(i1).equals(d2.get(i2))) { // agreement on next dimension
                String s1 = v1.get(i1), s2 = v2.get(i2);
                if (s1 == null)
                    values.add(s2);
                else if (s2 == null || s1.equals(s2))
                    values.add(s1);
                else
                    return invalidBinding; // disagreement on next value

                dimensions.add(d1.get(i1));
                i1++;
                i2++;
            }
            else if ( ! d2.contains(d1.get(i1))) { // next dimension in d1 is independent from d2
                dimensions.add(d1.get(i1));
                values.add(v1.get(i1));
                i1++;
            }
            else if ( ! d1.contains(d2.get(i2))) { // next dimension in d2 is independent from d1
                dimensions.add(d2.get(i2));
                values.add(v2.get(i2));
                i2++;
            }
            else {
                return invalidBinding; // not independent and no agreement
            }
        }
        while (i1 < d1.size()) {
            dimensions.add(d1.get(i1));
            values.add(v1.get(i1));
            i1++;
        }
        while (i2 < d2.size()) {
            dimensions.add(d2.get(i2));
            values.add(v2.get(i2));
            i2++;
        }

        return DimensionBinding.createFrom(dimensions, DimensionValues.createFrom(values.toArray(new String[0])));
    }
Combines this binding with another if compatible.
Two bindings are incompatible if
<ul>
    <li>They contain a different value for the same key, or</li>
    <li>They contain the same pair of dimensions in a different order</li>
</ul>

@return the combined binding, or the special invalidBinding if these two bindings are incompatible
container-search/src/main/java/com/yahoo/search/query/profile/DimensionBinding.java