<commit_before>package com.github.martincooper.datatable;

import io.vavr.collection.Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;

/**
 * LambdaCollect. Custom Collector.
 * Used to pass the contents of a collection to a
 * single method, returning a single value.
 *
 * @param <T> The collection type.
 * @param <U> The return type.
 */
public class LambdaCollect<T, U> implements Collector<T, ArrayList<T>, U> {

    private final Function<Stream<T>, U> function;

    /**
     * LambdaCollect constructor.
     *
     * @param function The function to run on the collected items.
     */
    public LambdaCollect(Function<Stream<T>, U> function) {
        this.function = function;
    }

    /**
     * as method. Static helper to return a new instance of the Lambda Collector class.
     *
     * @param function The function to run on the full collection.
     * @param <T> The collection type.
     * @param <U> The return type.
     * @return
     */
    public static <T, U> LambdaCollect<T, U> as(Function<Stream<T>, U> function) {
        return new LambdaCollect<>(function);
    }

    /**
     * The supplier. Returns a new ArrayList which
     * builds up the final item list.
     *
     * @return Returns the ArrayList.
     */
    @Override
    public Supplier<ArrayList<T>> supplier() {
        return new Supplier<ArrayList<T>>() {
            @Override
            public ArrayList<T> get() {
                return new ArrayList<T>();
            }
        } ;
    }

    /**
     * The accumulator. In this case, just append the item to the list.
     *
     * @return Return the ArrayList
     */
    @Override
    public BiConsumer<ArrayList<T>, T> accumulator() {
        return ArrayList::add;
    }

    // Not implemented : Parallel Stream.
    @Override
    public BinaryOperator<ArrayList<T>> combiner() {
        return (acc1, acc2) -> {
            throw new UnsupportedOperationException();
        };
    }

    /**
     * The finisher has all the items in the list. Now we just need
     * to run the requested lambda function on it to get the final results.
     *
     * @return Returns the result after passed through the lambda.
     */
    @Override
    public Function<ArrayList<T>, U> finisher() {
        return (acc) -> function.apply(Stream.ofAll(acc));
    }


    /**
     * Default set of characteristics.
     *
     * @return Returns the default set of characteristics.
     */
    @Override
    public Set<Characteristics> characteristics() {
        return Collections.emptySet();
    }
}<commit_msg>Modifying LambdaCollector.<commit_after>package com.github.martincooper.datatable;

import io.vavr.collection.Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;

/**
 * LambdaCollect. Custom Collector.
 * Used to pass the contents of a collection to a
 * single method, returning a single value.
 *
 * @param <T> The collection type.
 * @param <U> The return type.
 */
public class LambdaCollect<T, U> implements Collector<T, ArrayList<T>, U> {

    private final Function<Stream<T>, U> function;

    /**
     * LambdaCollect constructor.
     *
     * @param function The function to run on the collected items.
     */
    public LambdaCollect(Function<Stream<T>, U> function) {
        this.function = function;
    }

    /**
     * as method. Static helper to return a new instance of the Lambda Collector class.
     *
     * @param function The function to run on the full collection.
     * @param <T> The collection type.
     * @param <U> The return type.
     * @return Returns a new instance of the collector.
     */
    public static <T, U> LambdaCollect<T, U> as(Function<Stream<T>, U> function) {
        return new LambdaCollect<>(function);
    }

    /**
     * The supplier. Returns a new ArrayList which
     * builds up the final item list.
     *
     * @return Returns the ArrayList.
     */
    @Override
    public Supplier<ArrayList<T>> supplier() {
        return ArrayList::new;
    }

    /**
     * The accumulator. In this case, just append the item to the list.
     *
     * @return Return the ArrayList
     */
    @Override
    public BiConsumer<ArrayList<T>, T> accumulator() {
        return ArrayList::add;
    }

    // Not implemented : Parallel Stream.
    @Override
    public BinaryOperator<ArrayList<T>> combiner() {
        return (acc1, acc2) -> {
            throw new UnsupportedOperationException();
        };
    }

    /**
     * The finisher has all the items in the list. Now we just need
     * to run the requested lambda function on it to get the final results.
     *
     * @return Returns the result after passed through the lambda.
     */
    @Override
    public Function<ArrayList<T>, U> finisher() {
        return (items) -> function.apply(Stream.ofAll(items));
    }


    /**
     * Default set of characteristics.
     *
     * @return Returns the default set of characteristics.
     */
    @Override
    public Set<Characteristics> characteristics() {
        return Collections.emptySet();
    }
}
{'fraction_non_alphanumeric': 0.10474452554744526, 'fraction_numerical': 0.00072992700729927, 'mean_word_length': 2.5406976744186047, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 61, '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': '7487800', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1509, 'n_words': 510}