private static Predicate convertConjunction(Conjunction conjunction, long nValidOperands) {
        List<Predicate> operands = conjunction.getOperands();
        // All operands are instance of FeatureSet are valid and may therefor be placed into a single FeatureConjunction.
        if (nValidOperands == operands.size()) {
            return new FeatureConjunction(operands);
        }

        List<Predicate> invalidFeatureConjunctionOperands = new ArrayList<>();
        List<Map<String, Predicate>> featureConjunctionOperandsList = new ArrayList<>();
        featureConjunctionOperandsList.add(new TreeMap<>());
        for (Predicate operand : operands) {
            if (FeatureConjunction.isValidFeatureConjunctionOperand(operand)) {
                addFeatureConjunctionOperand(featureConjunctionOperandsList, operand);
            } else {
                invalidFeatureConjunctionOperands.add(operand);
            }
        }

        // Create a Conjunction root.
        Conjunction newConjunction = new Conjunction();
        newConjunction.addOperands(invalidFeatureConjunctionOperands);
        // For all operand partitions: create FeatureConjunction if partition has more than a single predicate.
        for (Map<String, Predicate> featureConjunctionOperands : featureConjunctionOperandsList) {
            Collection<Predicate> values = featureConjunctionOperands.values();
            if (featureConjunctionOperands.size() == 1) {
                // Add single operand directly to root conjunction.
                newConjunction.addOperands(values);
            } else {
                newConjunction.addOperand(new FeatureConjunction(new ArrayList<>(values)));
            }
        }
        return newConjunction;
    }
Conversion rules:
 1) A {@link FeatureConjunction} may only consist of FeatureSets having unique keys.
    If multiple {@link FeatureSet} share the same key, they have to be placed into separate FeatureConjunctions.
 2) A FeatureConjunction must have at least 2 operands.
 3) Any operand that is not a FeatureSet, negated or not,
    (e.g {@link FeatureRange}) cannot be placed into a FeatureConjunction.
 4) All FeatureSets may only have a single value.

 See the tests in FeatureConjunctionTransformerTest for conversion examples.
predicate-search/src/main/java/com/yahoo/search/predicate/optimization/FeatureConjunctionTransformer.java