<commit_before>package com.w11k.lsql;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ForwardingMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.joda.time.DateTime;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;

/**
 *
 */
public class Row extends ForwardingMap<String, Object> {

    private Map<String, Object> data;

    public static Row fromKeyVals(Object... keyVals) {
        Row r = new Row();
        r.addKeyVals(keyVals);
        return r;
    }

    public Row() {
        this(Maps.<String, Object>newHashMap());
    }

    public Row(Map<String, Object> data) {
        this.data = newHashMap(data);
    }

    public void setDelegate(Map<String, Object> data) {
        this.data = data;
    }

    public Row addKeyVals(Object... keyVals) {
        checkArgument(
                keyVals.length == 0 || keyVals.length % 2 == 0, "content must be a list of iterant key value pairs.");

        Iterable<List<Object>> partition = Iterables.partition(newArrayList(keyVals), 2);
        for (List<Object> objects : partition) {
            Object key = objects.get(0);
            checkArgument(key instanceof String, "argument " + key + " is not a String");
            Object value = objects.get(1);
            put(key.toString(), value);
        }
        return this;
    }

    @Override
    public Object put(String key, Object value) {
        return super.put(key, value);
    }

    public List<String> getKeyList() {
        return Lists.newLinkedList(keySet());
    }

    public <A> A getAs(Class<A> type, String key) {
        if (!containsKey(key)) {
            throw new IllegalArgumentException("No entry for key '" + key + "'.");
        }
        Object value = get(key);
        if (value == null) {
            return null;
        }
        if (!type.isAssignableFrom(value.getClass())) {
            A converted = convertWithJackson(type, value);
            put(key, converted);
            return converted;
        }
        return type.cast(value);
    }

    public Optional<Object> getOptional(String key) {
        return Optional.fromNullable(get(key));
    }

    public Integer getInt(String key) {
        return getAs(Integer.class, key);
    }

    public Long getLong(String key) {
        return getAs(Long.class, key);
    }
<commit_msg>Row.getAsOr added<commit_after>package com.w11k.lsql;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ForwardingMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.joda.time.DateTime;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;

/**
 *
 */
public class Row extends ForwardingMap<String, Object> {

    private Map<String, Object> data;

    public static Row fromKeyVals(Object... keyVals) {
        Row r = new Row();
        r.addKeyVals(keyVals);
        return r;
    }

    public Row() {
        this(Maps.<String, Object>newHashMap());
    }

    public Row(Map<String, Object> data) {
        this.data = newHashMap(data);
    }

    public void setDelegate(Map<String, Object> data) {
        this.data = data;
    }

    public Row addKeyVals(Object... keyVals) {
        checkArgument(
                keyVals.length == 0 || keyVals.length % 2 == 0, "content must be a list of iterant key value pairs.");

        Iterable<List<Object>> partition = Iterables.partition(newArrayList(keyVals), 2);
        for (List<Object> objects : partition) {
            Object key = objects.get(0);
            checkArgument(key instanceof String, "argument " + key + " is not a String");
            Object value = objects.get(1);
            put(key.toString(), value);
        }
        return this;
    }

    @Override
    public Object put(String key, Object value) {
        return super.put(key, value);
    }

    public List<String> getKeyList() {
        return Lists.newLinkedList(keySet());
    }

    public <A> A getAs(Class<A> type, String key) {
        if (!containsKey(key)) {
            throw new IllegalArgumentException("No entry for key '" + key + "'.");
        }
        Object value = get(key);
        if (value == null) {
            return null;
        }
        if (!type.isAssignableFrom(value.getClass())) {
            A converted = convertWithJackson(type, value);
            put(key, converted);
            return converted;
        }
        return type.cast(value);
    }

    public <A> A getAsOr(Class<A> type, String key, A defaultValue) {
        if (!containsKey(key)) {
            return defaultValue;
        }
        return getAs(type, key);
    }

    public Optional<Object> getOptional(String key) {
        return Optional.fromNullable(get(key));
    }

    public Integer getInt(String key) {
        return getAs(Integer.class, key);
    }

    public Long getLong(String key) {
        return getAs(Long.class, key);
    }

{'fraction_non_alphanumeric': 0.11956521739130435, 'fraction_numerical': 0.0027605244996549345, 'mean_word_length': 2.5916976456009913, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5620423', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1692, 'n_words': 409}