private Item combineItems(Item first, Item second, TermType termType) {
        if (first instanceof NullItem) {
            return second;
        } else if (first instanceof NotItem notItem) {
            if (termType == TermType.NOT) {
                notItem.addNegativeItem(second);
            }
            else {
                Item newPositive = combineItems(notItem.getPositiveItem(), second, termType);
                notItem.setPositiveItem(newPositive);
            }
            return notItem;
        }
        else if (first instanceof CompositeItem composite) {
            CompositeItem combined = createType(termType);
            if (combined.getClass().equals(composite.getClass())) {
                composite.addItem(second);
                return composite;
            }
            else {
                if (combined instanceof EquivItem) {
                    first = makeEquivCompatible(first);
                    second = makeEquivCompatible(second);
                }
                combined.addItem(first);
                combined.addItem(second); // Also works for nots
                return combined;
            }
        }
        else if (first instanceof TermItem) {
            CompositeItem combined = createType(termType);
            combined.addItem(first);
            combined.addItem(second);
            return combined;
        }
        else {
            throw new RuntimeException("Don't know how to add an item to type " + first.getClass());
        }
    }
A special purpose check used to simplify the above
container-search/src/main/java/com/yahoo/prelude/semantics/engine/Evaluation.java