<commit_before>package hudson.util;

import hudson.model.AbstractBuild;
import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Node;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.View;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;

/**
 * {@link List} of {@link Run}s.
 *
 * @author <NAME>
 */
public class RunList extends ArrayList<Run> {

    public RunList() {
    }

    public RunList(Job<?,?> j) {
        addAll(j.getBuilds());
    }

    public RunList(View view) {
        for (Item item : view.getItems())
            for (Job<?,?> j : item.getAllJobs())
                addAll(j.getBuilds());
        Collections.sort(this,Run.ORDER_BY_DATE);
    }

    public RunList(Collection<? extends Job> jobs) {
        for (Job<?,?> j : jobs)
            addAll(j.getBuilds());
        Collections.sort(this,Run.ORDER_BY_DATE);
    }

    public static RunList fromRuns(Collection<? extends Run> runs) {
        RunList r = new RunList();
        r.addAll(runs);
        return r;
    }

    /**
     * Filter the list to non-successful builds only.
     */
    public RunList failureOnly() {
        for (Iterator<Run> itr = iterator(); itr.hasNext();) {
            Run r = itr.next();
            if(r.getResult()==Result.SUCCESS)
                itr.remove();
        }
        return this;
    }

    /**
     * Filter the list to builds on a single node only
     */
    public RunList node(Node node) {
        for (Iterator<Run> itr = iterator(); itr.hasNext();) {
            Run r = itr.next();
            if (r instanceof AbstractBuild) {
            	if (!((AbstractBuild) r).getBuiltOn().equals(node)) {
                    itr.remove();
            	}
            }
        }
        return this;
    }

    /**
     * Filter the list to regression builds only.
     */
    public RunList regressionOnly() {
        for (Iterator<Run> itr = iterator(); itr.hasNext();) {
            Run r = itr.next();
            if(!r.getBuildStatusSummary().isWorse)
                itr.remove();
        }<commit_msg>[FIXED HUDSON-2622] Fixed possible NPE when rendering a build history after a slave removal.<commit_after>package hudson.util;

import hudson.model.AbstractBuild;
import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Node;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.View;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;

/**
 * {@link List} of {@link Run}s.
 *
 * @author <NAME>
 */
public class RunList extends ArrayList<Run> {

    public RunList() {
    }

    public RunList(Job<?,?> j) {
        addAll(j.getBuilds());
    }

    public RunList(View view) {
        for (Item item : view.getItems())
            for (Job<?,?> j : item.getAllJobs())
                addAll(j.getBuilds());
        Collections.sort(this,Run.ORDER_BY_DATE);
    }

    public RunList(Collection<? extends Job> jobs) {
        for (Job<?,?> j : jobs)
            addAll(j.getBuilds());
        Collections.sort(this,Run.ORDER_BY_DATE);
    }

    public static RunList fromRuns(Collection<? extends Run> runs) {
        RunList r = new RunList();
        r.addAll(runs);
        return r;
    }

    /**
     * Filter the list to non-successful builds only.
     */
    public RunList failureOnly() {
        for (Iterator<Run> itr = iterator(); itr.hasNext();) {
            Run r = itr.next();
            if(r.getResult()==Result.SUCCESS)
                itr.remove();
        }
        return this;
    }

    /**
     * Filter the list to builds on a single node only
     */
    public RunList node(Node node) {
        for (Iterator<Run> itr = iterator(); itr.hasNext();) {
            Run r = itr.next();
            if (r instanceof AbstractBuild) {
            	if (((AbstractBuild)r).getBuiltOn()!=node) {
                    itr.remove();
            	}
            }
        }
        return this;
    }

    /**
     * Filter the list to regression builds only.
     */
    public RunList regressionOnly() {
        for (Iterator<Run> itr = iterator(); itr.hasNext();) {
            Run r = itr.next();
            if(!r.getBuildStatusSummary().isWorse)
                itr.remove();
        }
{'fraction_non_alphanumeric': 0.13342198581560283, 'fraction_numerical': 0.0008865248226950354, 'mean_word_length': 2.095336076817558, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '241826', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1366, 'n_words': 332}