<commit_before>package valandur.webapi.servlets;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.reflections.Reflections;
import org.spongepowered.api.event.Event;
import valandur.webapi.WebAPI;
import valandur.webapi.misc.Permission;
import valandur.webapi.cache.DataCache;
import valandur.webapi.json.JsonConverter;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.Set;

public class ClassServlet extends WebAPIServlet {

    @Override
    @Permission(perm = "class")
    protected void handleGet(ServletData data) {
        String[] paths = data.getPathParts();

        if (paths.length == 0 || paths[0].isEmpty()) {
            String baseClass = data.getQueryPart("baseClass");
            if (baseClass != null) {
                try {
                    Class<?> c = Class.forName(baseClass);

                    WebAPI.getInstance().getLogger().info("Discovering all subclasses of '" + baseClass + "'...");
                    Set classes = WebAPI.getInstance().getReflections().getSubTypesOf(c);
                    WebAPI.getInstance().getLogger().info("Found " + classes.size() + " subclasses of '" + baseClass + "'");

                    data.addJson("base", c.getName());
                    data.addJson("classes", classes);
                } catch (ClassNotFoundException e) {
                    data.sendError(HttpServletResponse.SC_NOT_FOUND, "The class '" + baseClass + "' could not be found");
                }
            } else {
                ArrayNode node = JsonNodeFactory.instance.arrayNode();
                data.addJson("classes", JsonConverter.toJson(DataCache.getClasses().keySet().stream().map(Class::getName).toArray(String[]::new)));
            }
            return;
        }

        String className = paths[0];
        for (Map.Entry<Class, JsonNode> entry : DataCache.getClasses().entrySet()) {
            if (entry.getKey().getSimpleName().equalsIgnoreCase(className)) {
                data.addJson("class", entry.getValue());
                return;
            }
        }

        try {
            Class c = Class.forName(className);
            data.addJson("class", DataCache.getClass(c));
        } catch (ClassNotFoundException e) {
            data.sendError(HttpServletResponse.SC_NOT_FOUND, "The class '" + className + "' could not be found");
        }
    }
}<commit_msg>fix(class): Rework class endpoint urls<commit_after>package valandur.webapi.servlets;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.reflections.Reflections;
import org.spongepowered.api.event.Event;
import valandur.webapi.WebAPI;
import valandur.webapi.misc.Permission;
import valandur.webapi.cache.DataCache;
import valandur.webapi.json.JsonConverter;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.Set;

public class ClassServlet extends WebAPIServlet {

    @Override
    @Permission(perm = "class")
    protected void handleGet(ServletData data) {
        String[] paths = data.getPathParts();

        if (paths.length == 0 || paths[0].isEmpty()) {
            ArrayNode node = JsonNodeFactory.instance.arrayNode();
            data.addJson("classes", JsonConverter.toJson(DataCache.getClasses().keySet().stream().map(Class::getName).toArray(String[]::new)));
            return;
        }

        String className = paths[0];

        try {
            Class c = Class.forName(className);

            if (paths.length <= 1) {
                data.addJson("class", DataCache.getClass(c));
                return;
            }

            String op = paths[1];
            if (op.equalsIgnoreCase("subclasses")) {
                WebAPI.getInstance().getLogger().info("Discovering all subclasses of '" + c.getName() + "'...");
                Set classes = WebAPI.getInstance().getReflections().getSubTypesOf(c);
                WebAPI.getInstance().getLogger().info("Found " + classes.size() + " subclasses of '" + c.getName() + "'");

                data.addJson("base", c.getName());
                data.addJson("classes", classes);
            } else {
                data.sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown operation '" + op + "'");
            }
        } catch (ClassNotFoundException e) {
            data.sendError(HttpServletResponse.SC_NOT_FOUND, "The class '" + className + "' could not be found");
        }
    }
}
{'fraction_non_alphanumeric': 0.1319204152249135, 'fraction_numerical': 0.0017301038062283738, 'mean_word_length': 2.5576923076923075, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '6812977', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1244, 'n_words': 226}