<commit_before>package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete;

import com.mjrichardson.teamCity.buildTriggers.*;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class Environment {
    @NotNull
    public final String environmentId;
    @NotNull
    public OctopusDate latestDeployment;
    @NotNull
    public OctopusDate latestSuccessfulDeployment;
    @NotNull
    String releaseId;
    @NotNull
    String deploymentId;
    @NotNull
    String version;
    @NotNull
    String projectId;

    public Environment(@NotNull String environmentId,
                       @NotNull OctopusDate latestDeployment,
                       @NotNull OctopusDate latestSuccessfulDeployment,
                       @NotNull String releaseId,
                       @NotNull String deploymentId,
                       @NotNull String version,
                       @NotNull String projectId) {
        this.environmentId = environmentId;
        this.latestDeployment = latestDeployment;
        this.latestSuccessfulDeployment = latestSuccessfulDeployment;
        this.releaseId = releaseId;
        this.deploymentId = deploymentId;
        this.version = version;
        this.projectId = projectId;
    }

    public boolean isLatestDeploymentOlderThan(OctopusDate compareDate) {
        return this.latestDeployment.compareTo(compareDate) < 0;
    }

    public boolean isLatestSuccessfulDeploymentOlderThen(OctopusDate compareDate) {
        return this.latestSuccessfulDeployment.compareTo(compareDate) < 0;
    }

    public boolean wasLatestDeploymentSuccessful() {
        return this.latestSuccessfulDeployment.compareTo(this.latestDeployment) == 0;
    }

    public boolean hasHadAtLeastOneSuccessfulDeployment() {
        return this.latestSuccessfulDeployment.compareTo(new NullOctopusDate()) > 0;
    }

    public void update(OctopusDate latestDeployment, Boolean finishedSuccessfully) {
        if (isLatestDeploymentOlderThan(latestDeployment)) {
            this.latestDeployment = latestDeployment;
        }
        if (finishedSuccessfully && isLatestSuccessfulDeploymentOlderThen(latestDeployment)) {
            latestSuccessfulDeployment = latestDeployment;
        }
    }

    @Override
    public String toString() {
        return String.format("%s;%s;%s;%s;%s;%s;%s", environmentId, latestDeployment, latestSuccessfulDeployment, releaseId, deploymentId, version, projectId);
    }

    public static Environment Parse(String toStringRepresentation) throws NeedToDeleteAndRecreateTrigger {
        final String[] split = toStringRepresentation.split(";");

        if (split.length < 4)
            throw new NeedToDeleteAndRecreateTrigger();

        final String environmentId = split[0];
        final OctopusDate latestDeployment = OctopusDate.Parse(split[1]);
        final OctopusDate latestSuccessfulDeployment = OctopusDate.Parse(split[2]);
        final String releaseId = split[3];
        final String deploymentId = split[4];
        final String version = split[5];
        final String projectId = split[6];

        return new Environment(environmentId, latestDeployment, latestSuccessfulDeployment, releaseId, deploymentId, version, projectId);
    }<commit_msg>Fix handling of environments with no deployments<commit_after>package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete;

import com.mjrichardson.teamCity.buildTriggers.*;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class Environment {
    @NotNull
    public final String environmentId;
    @NotNull
    public OctopusDate latestDeployment;
    @NotNull
    public OctopusDate latestSuccessfulDeployment;
    @NotNull
    String releaseId;
    @NotNull
    String deploymentId;
    @NotNull
    String version;
    @NotNull
    String projectId;

    public Environment(@NotNull String environmentId,
                       @NotNull OctopusDate latestDeployment,
                       @NotNull OctopusDate latestSuccessfulDeployment,
                       @NotNull String releaseId,
                       @NotNull String deploymentId,
                       @NotNull String version,
                       @NotNull String projectId) {
        this.environmentId = environmentId;
        this.latestDeployment = latestDeployment;
        this.latestSuccessfulDeployment = latestSuccessfulDeployment;
        this.releaseId = releaseId;
        this.deploymentId = deploymentId;
        this.version = version;
        this.projectId = projectId;
    }

    public boolean isLatestDeploymentOlderThan(OctopusDate compareDate) {
        return this.latestDeployment.compareTo(compareDate) < 0;
    }

    public boolean isLatestSuccessfulDeploymentOlderThen(OctopusDate compareDate) {
        return this.latestSuccessfulDeployment.compareTo(compareDate) < 0;
    }

    public boolean wasLatestDeploymentSuccessful() {
        return this.latestSuccessfulDeployment.compareTo(this.latestDeployment) == 0;
    }

    public boolean hasHadAtLeastOneSuccessfulDeployment() {
        return this.latestSuccessfulDeployment.compareTo(new NullOctopusDate()) > 0;
    }

    public void update(OctopusDate latestDeployment, Boolean finishedSuccessfully) {
        if (isLatestDeploymentOlderThan(latestDeployment)) {
            this.latestDeployment = latestDeployment;
        }
        if (finishedSuccessfully && isLatestSuccessfulDeploymentOlderThen(latestDeployment)) {
            latestSuccessfulDeployment = latestDeployment;
        }
    }

    @Override
    public String toString() {
        return String.format("%s;%s;%s;%s;%s;%s;%s", environmentId, latestDeployment, latestSuccessfulDeployment, releaseId, deploymentId, version, projectId);
    }

    public static Environment Parse(String toStringRepresentation) throws NeedToDeleteAndRecreateTrigger {
        final Integer DONT_REMOVE_EMPTY_VALUES = -1;
        final String[] split = toStringRepresentation.split(";", DONT_REMOVE_EMPTY_VALUES);

        if (split.length < 4)
            throw new NeedToDeleteAndRecreateTrigger();

        final String environmentId = split[0];
        final OctopusDate latestDeployment = OctopusDate.Parse(split[1]);
        final OctopusDate latestSuccessfulDeployment = OctopusDate.Parse(split[2]);
        final String releaseId = split[3];
        final String deploymentId = split[4];
        final String version = split[5];
        final String projectId = split[6];

        return new Environment(environmentId, latestDeployment, latestSuccessfulDeployment, releaseId, deploymentId, version, projectId);
    }
{'fraction_non_alphanumeric': 0.07238037552998183, 'fraction_numerical': 0.0037855844942459114, 'mean_word_length': 3.180379746835443, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '6083548', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1667, 'n_words': 373}