All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.farao_community.farao.swe.runner.api.resource.ThreadLauncherResult Maven / Gradle / Ivy

There is a newer version: 1.28.0
Show newest version
/*
 * Copyright (c) 2022, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.farao_community.farao.swe.runner.api.resource;

import java.util.Optional;

/**
 * @author Theo Pascoli {@literal }
 */
public class ThreadLauncherResult {

    private final Optional result;
    private final boolean hasError;
    private final Exception exception;

    public ThreadLauncherResult(Optional result, boolean hasError, Exception exception) {
        this.result = result;
        this.hasError = hasError;
        this.exception = exception;
    }

    public static  ThreadLauncherResult success(U result) {
        return new ThreadLauncherResult<>(Optional.of(result), false, null);
    }

    public static  ThreadLauncherResult interrupt() {
        return new ThreadLauncherResult<>(Optional.empty(), false, null);
    }

    public static  ThreadLauncherResult error(Exception e) {
        return new ThreadLauncherResult<>(Optional.empty(), true, e);
    }

    public Optional getResult() {
        return result;
    }

    public boolean hasError() {
        return hasError;
    }

    public Exception getException() {
        return exception;
    }
}