<commit_before>package se.arbetsformedlingen.venice.probe;

import se.arbetsformedlingen.venice.common.Server;
import se.arbetsformedlingen.venice.common.Application;
import se.arbetsformedlingen.venice.common.Environment;

import java.util.List;
import java.util.Set;
import java.util.HashSet;

import org.json.JSONObject;
import org.json.JSONArray;

public class JsonRespnseBuilder {
    private LatestProbeStatuses statuses;

    public JsonRespnseBuilder(LatestProbeStatuses statuses) {
        this.statuses = statuses;
    }

    public String build(List<Server> servers) {
        Set<Application> apps = new HashSet<>();
        servers.stream().forEach(srv -> {
            apps.add(srv.getApplication());
        });

        Set<Environment> envs = new HashSet<>();
        servers.stream().forEach(srv -> {
            envs.add(srv.getEnvironment());
        });

        JSONArray response = new JSONArray();
        for (Application app : apps) {
            JSONObject appObj = new JSONObject();
            appObj.put("name", app.getName());

            JSONArray envList = new JSONArray();
            for (Environment env : envs) {
                JSONObject envObj = new JSONObject();
                envObj.put("name", env.getName());

                JSONObject serverList = new JSONObject();
                for (Server server : servers) {
                    if (!app.equals(server.getApplication())) {
                        continue;
                    }
                    if (!env.equals(server.getEnvironment())) {
                        continue;
                    }

                    ProbeResponse probeRes = statuses.getStatus(server);

                    JSONObject serverObj = new JSONObject();
                    serverObj.put("status", probeRes.getStatus());
                    serverObj.put("version", probeRes.getVersion());

                    serverList.put(server.getHost().toString(), serverObj);
                }

                envObj.put("servers", serverList);

                envList.put(envObj);
            }

            response.put(appObj);
        }

        return response.toString();
    }
}<commit_msg>Collect the apps and envs in ordered lists intead of unordered sets<commit_after>package se.arbetsformedlingen.venice.probe;

import org.json.JSONArray;
import org.json.JSONObject;
import se.arbetsformedlingen.venice.common.Application;
import se.arbetsformedlingen.venice.common.Environment;
import se.arbetsformedlingen.venice.common.Server;

import java.util.LinkedList;
import java.util.List;

public class JsonRespnseBuilder {
    private LatestProbeStatuses statuses;

    public JsonRespnseBuilder(LatestProbeStatuses statuses) {
        this.statuses = statuses;
    }

    public String build(List<Server> servers) {
        List<Application> apps = new LinkedList<>();
        servers.forEach(srv -> {
            Application application = srv.getApplication();
            if (!apps.contains(application)) {
                apps.add(application);
            }
        });

        List<Environment> envs = new LinkedList<>();
        servers.forEach(srv -> {
            Environment environment = srv.getEnvironment();
            if (!envs.contains(environment)) {
                envs.add(environment);
            }
        });

        JSONArray response = new JSONArray();
        for (Application app : apps) {
            JSONObject appObj = new JSONObject();
            appObj.put("name", app.getName());

            JSONArray envList = new JSONArray();
            for (Environment env : envs) {

                JSONObject envObj = new JSONObject();
                envObj.put("name", env.getName());

                JSONObject serverList = new JSONObject();
                for (Server server : servers) {
                    if (!app.equals(server.getApplication())) {
                        continue;
                    }
                    if (!env.equals(server.getEnvironment())) {
                        continue;
                    }

                    ProbeResponse probeRes = statuses.getStatus(server);

                    JSONObject serverObj = new JSONObject();
                    serverObj.put("status", probeRes.getStatus());
                    serverObj.put("version", probeRes.getVersion());

                    serverList.put(server.getHost().toString(), serverObj);
                }

                envObj.put("servers", serverList);

                envList.put(envObj);
            }
            appObj.put("environments", envList);

            response.put(appObj);
        }

        return response.toString();
    }
}
{'fraction_non_alphanumeric': 0.10824742268041238, 'fraction_numerical': 0.0, 'mean_word_length': 1.8518064911206369, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '4742263', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1152, 'n_words': 233}