<commit_before>package edu.cmu.cs.db.peloton.test.generate.ast;

import com.google.common.collect.ImmutableList;
import edu.cmu.cs.db.peloton.test.generate.Context;

import java.util.Iterator;
import java.util.List;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * Created by tianyuli on 3/22/17.
 */
public abstract class RecursiveElem extends ProductElem {
    protected abstract int numChildren();

    protected abstract Iterator<Ast.Clause> baseCase(Context context);

    protected abstract Iterator<Ast.Clause> recursiveCase(List<Supplier<Iterator<Ast.Clause>>> recursiveCases);

    @Override
    protected ImmutableList<Ast.Elem> args() {
        return null;
    }

    @Override
    protected String format(List<String> args) {
        return null;
    }

    @Override
    public Iterator<Ast.Clause> allClauses(Context context, int depth) {
        if (depth == 0) {
            return baseCase(context);
        }

        IntFunction<Supplier<Iterator<Ast.Clause>>> mapper = x -> (() -> allClauses(context, depth - 1));

        List<Supplier<Iterator<Ast.Clause>>> children = IntStream.range(0, numChildren())
                .mapToObj(mapper)
                .collect(Collectors.toList());

        return recursiveCase(children);
    }
}<commit_msg>Cleaned up RecursiveElem code<commit_after>package edu.cmu.cs.db.peloton.test.generate.ast;

import com.google.common.collect.ImmutableList;
import edu.cmu.cs.db.peloton.test.generate.Context;

import java.util.Iterator;
import java.util.List;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * Created by tianyuli on 3/22/17.
 */
public abstract class RecursiveElem implements Ast.Elem {
    protected abstract int numChildren();

    protected abstract Iterator<Ast.Clause> baseCase(Context context);

    protected abstract Iterator<Ast.Clause> recursiveCase(List<Supplier<Iterator<Ast.Clause>>> recursiveCases);


    @Override
    public Iterator<Ast.Clause> allClauses(Context context, int depth) {
        if (depth == 0) {
            return baseCase(context);
        }

        IntFunction<Supplier<Iterator<Ast.Clause>>> mapper = x -> (() -> allClauses(context, depth - 1));

        List<Supplier<Iterator<Ast.Clause>>> children = IntStream.range(0, numChildren())
                .mapToObj(mapper)
                .collect(Collectors.toList());

        return recursiveCase(children);
    }
}
{'fraction_non_alphanumeric': 0.11933359163115072, 'fraction_numerical': 0.006199147617202635, 'mean_word_length': 3.482638888888889, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7322758', 'n_tokens_mistral': 802, 'n_tokens_neox': 764, 'n_words': 154}