<commit_before>package de.comci.bitmap;

import com.google.common.collect.Lists;
import com.google.common.collect.Multiset;
import com.google.common.primitives.Ints;
import com.googlecode.javaewah.EWAHCompressedBitmap;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author <NAME> (<EMAIL>)
 */
public class BitMapCollection {

    private final static Logger LOG = LoggerFactory.getLogger(BitMapCollection.class);

    public static BasicSchemaBuilder create() {
        return new BasicSchemaBuilder();
    }

    public static DbSchemaBuilder create(Connection conn, String table, String... columns) {
        return new DbSchemaBuilder(conn, table, columns);
    }

    private final Map<String, BitMapDimension> dimensions;
    private final int columns;
    private final List<Object[]> raw = new ArrayList<>(10000);
    private boolean isReady;
    private int size = 0;

    BitMapCollection(Map<String, BitMapDimension> dimensions) {
        this.dimensions = dimensions;
        this.columns = dimensions.size();
    }

    public BitMapCollection add(List<Object[]> data) {
        data.forEach(d -> add(d));
        return this;
    }
    
    /**
     * Add a data tuple
     *
     * @param data
     * @return
     * @throws IllegalArgumentException if data.length does not equal the number
     * of dimensions
     * @throws IllegalArgumentException if the type of any object in data does
     * not match the dimensions type
     */
    public BitMapCollection add(final Object... data) {

        isReady = false;

        // check null
        if (data == null) {
            throw new IllegalArgumentException("null parameter not allowed");
        }

        // check length
        if (data.length != columns) {
            throw new IllegalArgumentException(String.format("column count does not match: expected %d, received %d", dimensions.size(), data.length));
        }

        // check types
        for (BitMapDimension d : dimensions.values()) {
            if (data[d.index] != null
                    && !d.getType().isAssignableFrom(data[d.index].getClass())) {
                throw new IllegalArgumentException();
            }
        }

        this.raw.add(data);

        return this;
    }

    /**
     * Synonym for {@link BitMapColumns#build()
     *
     * @return
     */
    BitMapCollection update() {
        return build();
    }

    /**
     * Generate the bit map data structures based upon the added data
     */
    BitMapCollection build() {
        long start = System.currentTimeMillis();
        int rows = raw.size();

        dimensions.values().parallelStream().forEach(d -> {
            for (int i = 0; i < rows; i++) {
                d.set(i, raw.get(i)[d.index]);
            }
        });<commit_msg>improved exception message<commit_after>package de.comci.bitmap;

import com.google.common.collect.Lists;
import com.google.common.collect.Multiset;
import com.google.common.primitives.Ints;
import com.googlecode.javaewah.EWAHCompressedBitmap;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author <NAME> (<EMAIL>)
 */
public class BitMapCollection {

    private final static Logger LOG = LoggerFactory.getLogger(BitMapCollection.class);

    public static BasicSchemaBuilder create() {
        return new BasicSchemaBuilder();
    }

    public static DbSchemaBuilder create(Connection conn, String table, String... columns) {
        return new DbSchemaBuilder(conn, table, columns);
    }

    private final Map<String, BitMapDimension> dimensions;
    private final int columns;
    private final List<Object[]> raw = new ArrayList<>(10000);
    private boolean isReady;
    private int size = 0;

    BitMapCollection(Map<String, BitMapDimension> dimensions) {
        this.dimensions = dimensions;
        this.columns = dimensions.size();
    }

    public BitMapCollection add(List<Object[]> data) {
        data.forEach(d -> add(d));
        return this;
    }
    
    /**
     * Add a data tuple
     *
     * @param data
     * @return
     * @throws IllegalArgumentException if data.length does not equal the number
     * of dimensions
     * @throws IllegalArgumentException if the type of any object in data does
     * not match the dimensions type
     */
    public BitMapCollection add(final Object... data) {

        isReady = false;

        // check null
        if (data == null) {
            throw new IllegalArgumentException("null parameter not allowed");
        }

        // check length
        if (data.length != columns) {
            throw new IllegalArgumentException(String.format("column count does not match: expected %d, received %d", dimensions.size(), data.length));
        }

        // check types
        for (BitMapDimension d : dimensions.values()) {
            if (data[d.index] != null
                    && !d.getType().isAssignableFrom(data[d.index].getClass())) {
                throw new IllegalArgumentException(String.format("supplied data type '%s' does not match expected '%s' for dimension '%s'", data[d.index].getClass(), d.getType(), d.getName()));
            }
        }

        this.raw.add(data);

        return this;
    }

    /**
     * Synonym for {@link BitMapColumns#build()
     *
     * @return
     */
    BitMapCollection update() {
        return build();
    }

    /**
     * Generate the bit map data structures based upon the added data
     */
    BitMapCollection build() {
        long start = System.currentTimeMillis();
        int rows = raw.size();

        dimensions.values().parallelStream().forEach(d -> {
            for (int i = 0; i < rows; i++) {
                d.set(i, raw.get(i)[d.index]);
            }
        });
{'fraction_non_alphanumeric': 0.11205140260147313, 'fraction_numerical': 0.0028208744710860366, 'mean_word_length': 2.557413600891862, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '7145073', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1723, 'n_words': 476}