public PredefinedFunction resolve(GroupingExpression exp) {
        if ((idx % 2) == 1) {
            throw new IllegalStateException("Missing to-limit of last bucket.");
        }
        int len = buckets.size();
        if (len == 0) {
            throw new IllegalStateException("Expected at least one bucket, got none.");
        }
        ConstantValue<?> begin = buckets.get(0).getFrom();
        ConstantValue<?> end = buckets.get(0).getTo();
        if (begin instanceof DoubleValue || end instanceof DoubleValue) {
            if (len == 1) {
                return new DoublePredefined(exp, (DoubleBucket)buckets.get(0));
            } else {
                return new DoublePredefined(exp, (DoubleBucket)buckets.get(0),
                                            buckets.subList(1, len).toArray(new DoubleBucket[len - 1]));
            }
        } else if (begin instanceof LongValue || end instanceof LongValue) {
            if (len == 1) {
                return new LongPredefined(exp, (LongBucket)buckets.get(0));
            } else {
                return new LongPredefined(exp, (LongBucket)buckets.get(0),
                                          buckets.subList(1, len).toArray(new LongBucket[len - 1]));
            }
        } else if (begin instanceof StringValue || end instanceof StringValue) {
            if (len == 1) {
                return new StringPredefined(exp, (StringBucket)buckets.get(0));
            } else {
                return new StringPredefined(exp, (StringBucket)buckets.get(0),
                                            buckets.subList(1, len).toArray(new StringBucket[len - 1]));
            }
        } else if (begin instanceof RawValue || end instanceof RawValue) {
            if (len == 1) {
                return new RawPredefined(exp, (RawBucket)buckets.get(0));
            } else {
                return new RawPredefined(exp, (RawBucket)buckets.get(0),
                                            buckets.subList(1, len).toArray(new RawBucket[len - 1]));
            }
        }
        throw new UnsupportedOperationException("Bucket type '" + begin.getClass() + "' not supported.");
    }
Resolves and returns the list of grouping expressions that correspond to the previously pushed buckets.

@param exp The expression to assign to the function.
@return The list corresponding to the pushed buckets.
container-search/src/main/java/com/yahoo/search/grouping/request/BucketResolver.java