class InputFieldComparator extends FieldComparator<Object> implements LeafFieldComparator {

    private final Object[] values;
    private final Input<?> input;
    private final List<? extends LuceneCollectorExpression<?>> collectorExpressions;
    private final Comparator<Object> comparator;
    private final @Nullable Object missingValue;
    private Object bottom;
    private Object top;

    InputFieldComparator(int numHits,
                         List<? extends LuceneCollectorExpression<?>> collectorExpressions,
                         Input<?> input,
                         Comparator<Object> comparator,
                         @Nullable Object missingValue) {
        this.collectorExpressions = collectorExpressions;
        this.comparator = comparator;
        this.missingValue = missingValue;
        this.values = new Object[numHits];
        this.input = input;
    }

    @Override
    public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
        for (int i = 0; i < collectorExpressions.size(); i++) {
            collectorExpressions.get(i).setNextReader(new ReaderContext(context));
        }
        return this;
    }

    @Override
    public int compare(int slot1, int slot2) {
        return comparator.compare(values[slot1], values[slot2]);
    }

    @Override
    public void setBottom(int slot) {
        bottom = values[slot];
    }

    @Override
    public void setTopValue(Object value) {
        top = value;
    }

    @Override
    public int compareBottom(int doc) throws IOException {
        for (int i = 0; i < collectorExpressions.size(); i++) {
            collectorExpressions.get(i).setNextDocId(doc);
        }
        return comparator.compare(bottom, getFirstNonNullOrNull(input.value(), missingValue));
    }

    @Nullable
    private static Object getFirstNonNullOrNull(Object first, Object second) {
        if (first != null) {
            return first;
        } else {
            return second;
        }
    }

    @Override
    public int compareTop(int doc) throws IOException {
        for (int i = 0; i < collectorExpressions.size(); i++) {
            collectorExpressions.get(i).setNextDocId(doc);
        }
        return comparator.compare(top, getFirstNonNullOrNull(input.value(), missingValue));
    }

    @Override
    public void copy(int slot, int doc) throws IOException {<FILL_FUNCTION_BODY>}

    @Override
    public void setScorer(Scorable scorer) {
    }

    @Override
    public Object value(int slot) {
        return values[slot];
    }
}

        for (int i = 0; i < collectorExpressions.size(); i++) {
            collectorExpressions.get(i).setNextDocId(doc);
        }
        Object value = input.value();
        if (value == null) {
            values[slot] = missingValue;
        } else {
            values[slot] = value;
        }
    
<no_super_class>