<commit_before>package com.nhl.link.move.df;

import com.nhl.link.move.df.map.DataRowToValueMapper;
import com.nhl.link.move.df.map.MapContext;
import com.nhl.link.move.df.zip.Zipper;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * An "index" of the DataFrame that provides access to column (and in the future potentially row) metadata.
 */
public abstract class Index {

    protected IndexPosition[] positions;
    private Map<String, IndexPosition> positionsIndex;

    protected Index(IndexPosition... positions) {
        this.positions = positions;
    }

    protected static IndexPosition[] continuousPositions(String... names) {
        IndexPosition[] positions = new IndexPosition[names.length];
        for (int i = 0; i < names.length; i++) {
            positions[i] = new IndexPosition(i, i, names[i]);
        }

        return positions;
    }

    protected static boolean isContinuous(IndexPosition... positions) {

        // true if starts with zero and increments by one

        if (positions.length > 0 && positions[0].rowIndex() > 0) {
            return false;
        }

        for (int i = 1; i < positions.length; i++) {
            if (positions[i].rowIndex() != positions[i - 1].rowIndex() + 1) {
                return false;
            }
        }

        return true;
    }

    public static Index withNames(String... names) {
        return new ContinuousIndex(continuousPositions(names));
    }

    public static Index withPositions(IndexPosition... positions) {
        return isContinuous(positions) ? new ContinuousIndex(positions) : new SparseIndex(positions);
    }

    public abstract Object[] compactCopy(Object[] row, Object[] to, int toOffset);

    public abstract Index rename(Map<String, String> oldToNewNames);

    public abstract Index compactIndex();

    public Index addNames(String... extraNames) {
        return Zipper.zipIndex(this, withNames(extraNames));
    }

    public <VR> Object[] addValues(MapContext context, Object[] row, DataRowToValueMapper<VR>... valueProducers) {
<commit_msg>DataFrame based micro-batches #161<commit_after>package com.nhl.link.move.df;

import com.nhl.link.move.df.map.DataRowToValueMapper;
import com.nhl.link.move.df.map.MapContext;
import com.nhl.link.move.df.zip.Zipper;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * An "index" of the DataFrame that provides access to column (and in the future potentially row) metadata.
 */
public abstract class Index {

    protected IndexPosition[] positions;
    private Map<String, IndexPosition> positionsIndex;

    protected Index(IndexPosition... positions) {
        this.positions = positions;
    }

    protected static IndexPosition[] continuousPositions(String... names) {
        IndexPosition[] positions = new IndexPosition[names.length];
        for (int i = 0; i < names.length; i++) {
            positions[i] = new IndexPosition(i, i, names[i]);
        }

        return positions;
    }

    protected static boolean isContinuous(IndexPosition... positions) {

        // true if starts with zero and increments by one

        if (positions.length > 0 && positions[0].rowIndex() > 0) {
            return false;
        }

        for (int i = 1; i < positions.length; i++) {
            if (positions[i].rowIndex() != positions[i - 1].rowIndex() + 1) {
                return false;
            }
        }

        return true;
    }

    public static Index withNames(String... names) {
        return new ContinuousIndex(continuousPositions(names));
    }

    public static Index withPositions(IndexPosition... positions) {
        return isContinuous(positions) ? new ContinuousIndex(positions) : new SparseIndex(positions);
    }

    public abstract Object[] compactCopy(Object[] row, Object[] to, int toOffset);

    public abstract Index rename(Map<String, String> oldToNewNames);

    public abstract Index compactIndex();

    public Object read(Object[] row, String columnName) {
        return position(columnName).read(row);
    }

    public Object read(Object[] row, int columnPos) {
        return getPositions()[columnPos].read(row);
    }

    public Index addNames(String... extraNames) {
        return Zipper.zipIndex(this, withNames(extraNames));
    }

    public <VR> Object[] addValues(MapContext context, Object[] row, DataRowToValueMapper<VR>... valueProducers) {

{'fraction_non_alphanumeric': 0.1143106457242583, 'fraction_numerical': 0.0037085514834205935, 'mean_word_length': 2.9696969696969697, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '937528', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1252, 'n_words': 353}