<commit_before>package io.honeybadger.reporter.dto;

import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.util.Scanner;

/**
 * Class containing statistics about the host system's load average.
 *
 * @author <a href="https://github.com/dekobon"><NAME></a>
 * @since 1.0.11
 */
public class Load implements Serializable {
    private static final long serialVersionUID = 3398000045209329774L;

    public final Number one;
    public final Number five;
    public final Number fifteen;

    public Load() {
        Number[] loadAverages = findLoadAverages();
        this.one = loadAverages[0];
        this.five = loadAverages[1];
        this.fifteen = loadAverages[2];
    }

    public Load(Number one, Number five, Number fifteen) {
        this.one = one;
        this.five = five;
        this.fifteen = fifteen;
    }

    /**
     * Attempts to find all three load values in a way that is safe for an in-process
     * operation. This leads to platform specific code. We attempt to avoid forking to
     * call external processes because this would be a bad thing to do on every error
     * that came into the system.
     *
     * @return an array containing all three load averages (1, 5, 15) in that order
     */
    static Number[] findLoadAverages() {
        OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
        String os = osBean.getName();

        if (os.equals("Linux")) {
            return findLinuxLoadAverages(osBean);
        } else {
            return defaultLoadAverages(osBean);
        }
    }

    static Number[] findLinuxLoadAverages(OperatingSystemMXBean osBean) {
        File loadavg = new File("/proc/loadavg");

        if (loadavg.exists() &&  loadavg.isFile() && loadavg.canRead()) {
            try (Scanner scanner = new Scanner(loadavg)) {
                if (!scanner.hasNext()) {
                    return defaultLoadAverages(osBean);
                }

                String line = scanner.nextLine();
                String[] values = line.split(" ", 4);

                return new Number[]{
                        Double.parseDouble(values[0]),
                        Double.parseDouble(values[1]),
                        Double.parseDouble(values[2])
                };

            } catch (Exception e) {
                LoggerFactory.getLogger(Load.class)
                        .debug("Error reading /proc/loadavg", e);
                return defaultLoadAverages(osBean);
            }
        } else {
            LoggerFactory.getLogger(Load.class)
                    .debug("Couldn't fid or access /proc/loadavg");
            return defaultLoadAverages(osBean);
        }
    }

    static Number[] defaultLoadAverages(OperatingSystemMXBean osBean) {
        return new Number[] { osBean.getSystemLoadAverage(), -1, -1 };
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Load load = (Load) o;

        if (one != null ? !one.equals(load.one) : load.one != null) return false;<commit_msg>Changed unknown five and fifteen to null instead of -1 as per #22.<commit_after>package io.honeybadger.reporter.dto;

import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.util.Scanner;

/**
 * Class containing statistics about the host system's load average.
 *
 * @author <a href="https://github.com/dekobon"><NAME></a>
 * @since 1.0.11
 */
public class Load implements Serializable {
    private static final long serialVersionUID = 3398000045209329774L;

    public final Number one;
    public final Number five;
    public final Number fifteen;

    public Load() {
        Number[] loadAverages = findLoadAverages();
        this.one = loadAverages[0];
        this.five = loadAverages[1];
        this.fifteen = loadAverages[2];
    }

    public Load(Number one, Number five, Number fifteen) {
        this.one = one;
        this.five = five;
        this.fifteen = fifteen;
    }

    /**
     * Attempts to find all three load values in a way that is safe for an in-process
     * operation. This leads to platform specific code. We attempt to avoid forking to
     * call external processes because this would be a bad thing to do on every error
     * that came into the system.
     *
     * @return an array containing all three load averages (1, 5, 15) in that order
     */
    static Number[] findLoadAverages() {
        OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
        String os = osBean.getName();

        if (os.equals("Linux")) {
            return findLinuxLoadAverages(osBean);
        } else {
            return defaultLoadAverages(osBean);
        }
    }

    static Number[] findLinuxLoadAverages(OperatingSystemMXBean osBean) {
        File loadavg = new File("/proc/loadavg");

        if (loadavg.exists() &&  loadavg.isFile() && loadavg.canRead()) {
            try (Scanner scanner = new Scanner(loadavg)) {
                if (!scanner.hasNext()) {
                    return defaultLoadAverages(osBean);
                }

                String line = scanner.nextLine();
                String[] values = line.split(" ", 4);

                return new Number[]{
                        Double.parseDouble(values[0]),
                        Double.parseDouble(values[1]),
                        Double.parseDouble(values[2])
                };

            } catch (Exception e) {
                LoggerFactory.getLogger(Load.class)
                        .debug("Error reading /proc/loadavg", e);
                return defaultLoadAverages(osBean);
            }
        } else {
            LoggerFactory.getLogger(Load.class)
                    .debug("Couldn't fid or access /proc/loadavg");
            return defaultLoadAverages(osBean);
        }
    }

    static Number[] defaultLoadAverages(OperatingSystemMXBean osBean) {
        return new Number[] { osBean.getSystemLoadAverage(), null, null };
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Load load = (Load) o;

        if (one != null ? !one.equals(load.one) : load.one != null) return false;
{'fraction_non_alphanumeric': 0.10398534127347686, 'fraction_numerical': 0.011452130096197893, 'mean_word_length': 2.171912832929782, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '7053901', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1743, 'n_words': 503}