<commit_before>package net.engin33r.luaspigot.lua;

import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;

/**
 * Utility class for validating arguments against {@link WeakType} types.
 */
public class TypeValidator {
    public static void validate(LuaTable val, String type) {
        LuaValue ttype = val.get("type");
        if (ttype == LuaValue.NIL) {
            LuaValue.error(type + " expected, got table");
        } else {
            String vtype = ttype.tojstring();
            if (!vtype.equals(type))
                LuaValue.error(type + " expected, got " + vtype);
        }
    }
}<commit_msg>Add more useful methods to TypeValidator<commit_after>package net.engin33r.luaspigot.lua;

import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;

/**
 * Utility class for validating arguments against {@link WeakType} types.
 */
public class TypeValidator {
    public static void validate(LuaTable val, String type) {
        LuaValue ttype = val.get("type");
        if (ttype == LuaValue.NIL) {
            LuaValue.error(type + " expected, got table");
        } else {
            String vtype = ttype.tojstring();
            if (!vtype.equals(type))
                LuaValue.error(type + " expected, got " + vtype);
        }
    }
    public static void validateOf(LuaTable tbl, String type) {
        for (int i = 1; i <= tbl.length(); i++) {
            LuaTable val = tbl.get(i).checktable(i);
            LuaValue ttype = val.get("type");
            if (ttype == LuaValue.NIL) {
                LuaValue.error("table of " + type + " expected, got errant" +
                        " table");
            } else {
                String vtype = ttype.tojstring();
                if (!vtype.equals(type))
                    LuaValue.error("table of " + type + " expected, got" +
                            " errant " + vtype);
            }
        }
    }

    public static boolean is(LuaValue val, String type) {
        return val.type() == LuaValue.TTABLE &&
                val.get("type").tojstring().equals(type);
    }
}
{'fraction_non_alphanumeric': 0.12584704743465633, 'fraction_numerical': 0.004356243949661181, 'mean_word_length': 1.9570815450643777, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '7591949', 'n_tokens_mistral': 646, 'n_tokens_neox': 625, 'n_words': 149}