<commit_before>package org.ingrahamrobotics.robottables;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.ingrahamrobotics.robottables.api.RobotTable;
import org.ingrahamrobotics.robottables.api.TableType;
import org.ingrahamrobotics.robottables.api.UpdateAction;
import org.ingrahamrobotics.robottables.api.listeners.TableUpdateListener;
import org.ingrahamrobotics.robottables.interfaces.InternalTableHandler;
import org.ingrahamrobotics.robottables.interfaces.ProtocolTable;

public class InternalTable implements RobotTable, ProtocolTable {

    private final InternalTableHandler robotTables;
    private final Map<String, String> valueMap = new HashMap<String, String>(); // Map from String to String
    private final Map<String, String> adminMap = new HashMap<String, String>(); // Map from String to String
    private final List<TableUpdateListener> listeners = new ArrayList<TableUpdateListener>(); // List of TableUpdateListener
    private TableType type;
    private final String name;
    private long lastUpdate;
    /**
     * Whether this table is confirmed to be owned by us. This is only used internally.
     */
    private boolean readyToPublish;

    public InternalTable(final InternalTableHandler tables, final String name, final TableType initialType) {
        robotTables = tables;
        this.type = initialType;
        this.name = name;
    }

    public TableType getType() {
        return type;
    }

    void setType(TableType type) {
        this.type = type;
    }

    public long getLastUpdateTime() {
        if (type == TableType.LOCAL) {
            return System.currentTimeMillis();
        } else {
            return lastUpdate;
        }
    }

    public String getName() {
        return name;
    }

    public void updatedNow() {
        lastUpdate = System.currentTimeMillis();
    }

    public void setReadyToPublish(final boolean readyToPublish) {
        this.readyToPublish = readyToPublish;
    }

    public boolean isReadyToPublish() {
        return readyToPublish;
    }

    public void addUpdateListener(final TableUpdateListener listener) {
        if (!listeners.contains(listener)) {
            listeners.add(listener);
        }
    }

    public void remoteUpdateListener(final TableUpdateListener listener) {
        listeners.remove(listener);
    }

    public String get(final String key) {
        return valueMap.get(key);
    }

    public String get(final String key, final String defaultValue) {
        String value = valueMap.get(key);
        if (value == null) {
            value = defaultValue;
        }
        return value;
    }

    public int getInt(final String key) {
        String str = valueMap.get(key);
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException ex) {
            return 0;
        }
    }

    public int getInt(final String key, final int defaultValue) {
        String str = valueMap.get(key);
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    public double getDouble(final String key) {
        String str = (String) valueMap.get(key);
        try {
            return Double.parseDouble(str);
        } catch (NumberFormatException ex) {
            return 0.0;
        }
    }

    public double getDouble(final String key, final double defaultValue) {
        String str = (String) valueMap.get(key);
        try {
            return Double.parseDouble(str);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    public boolean getBoolean(final String key) {
        String str = valueMap.get(key);
        return ((str != null) && str.equalsIgnoreCase("true"));
    }

    public boolean getBoolean(final String key, final boolean defaultValue) {<commit_msg>Remove redundant casts (yay typed lists!)<commit_after>package org.ingrahamrobotics.robottables;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.ingrahamrobotics.robottables.api.RobotTable;
import org.ingrahamrobotics.robottables.api.TableType;
import org.ingrahamrobotics.robottables.api.UpdateAction;
import org.ingrahamrobotics.robottables.api.listeners.TableUpdateListener;
import org.ingrahamrobotics.robottables.interfaces.InternalTableHandler;
import org.ingrahamrobotics.robottables.interfaces.ProtocolTable;

public class InternalTable implements RobotTable, ProtocolTable {

    private final InternalTableHandler robotTables;
    private final Map<String, String> valueMap = new HashMap<String, String>(); // Map from String to String
    private final Map<String, String> adminMap = new HashMap<String, String>(); // Map from String to String
    private final List<TableUpdateListener> listeners = new ArrayList<TableUpdateListener>(); // List of TableUpdateListener
    private TableType type;
    private final String name;
    private long lastUpdate;
    /**
     * Whether this table is confirmed to be owned by us. This is only used internally.
     */
    private boolean readyToPublish;

    public InternalTable(final InternalTableHandler tables, final String name, final TableType initialType) {
        robotTables = tables;
        this.type = initialType;
        this.name = name;
    }

    public TableType getType() {
        return type;
    }

    void setType(TableType type) {
        this.type = type;
    }

    public long getLastUpdateTime() {
        if (type == TableType.LOCAL) {
            return System.currentTimeMillis();
        } else {
            return lastUpdate;
        }
    }

    public String getName() {
        return name;
    }

    public void updatedNow() {
        lastUpdate = System.currentTimeMillis();
    }

    public void setReadyToPublish(final boolean readyToPublish) {
        this.readyToPublish = readyToPublish;
    }

    public boolean isReadyToPublish() {
        return readyToPublish;
    }

    public void addUpdateListener(final TableUpdateListener listener) {
        if (!listeners.contains(listener)) {
            listeners.add(listener);
        }
    }

    public void remoteUpdateListener(final TableUpdateListener listener) {
        listeners.remove(listener);
    }

    public String get(final String key) {
        return valueMap.get(key);
    }

    public String get(final String key, final String defaultValue) {
        String value = valueMap.get(key);
        if (value == null) {
            value = defaultValue;
        }
        return value;
    }

    public int getInt(final String key) {
        String str = valueMap.get(key);
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException ex) {
            return 0;
        }
    }

    public int getInt(final String key, final int defaultValue) {
        String str = valueMap.get(key);
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    public double getDouble(final String key) {
        String str = valueMap.get(key);
        try {
            return Double.parseDouble(str);
        } catch (NumberFormatException ex) {
            return 0.0;
        }
    }

    public double getDouble(final String key, final double defaultValue) {
        String str = valueMap.get(key);
        try {
            return Double.parseDouble(str);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    public boolean getBoolean(final String key) {
        String str = valueMap.get(key);
        return ((str != null) && str.equalsIgnoreCase("true"));
    }

    public boolean getBoolean(final String key, final boolean defaultValue) {
{'fraction_non_alphanumeric': 0.08449809402795426, 'fraction_numerical': 0.0007623888182973316, 'mean_word_length': 2.594063926940639, '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': '2014853', 'n_tokens_mistral': 2110, 'n_tokens_neox': 2078, 'n_words': 573}