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

eu.maveniverse.maven.toolbox.shared.Result Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
/*
 * Copyright (c) 2023-2024 Maveniverse Org.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-v20.html
 */
package eu.maveniverse.maven.toolbox.shared;

import static java.util.Objects.requireNonNull;

import java.util.Optional;

/**
 * The Toolbox Commando result.
 */
public final class Result {
    public static  Result failure(String message) {
        requireNonNull(message, "message");
        return new Result<>(false, message, null);
    }

    public static  Result success(T data) {
        requireNonNull(data, "data");
        return new Result<>(true, "Success", data);
    }

    private final boolean success;
    private final String message;
    private final T data;

    private Result(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public Optional getData() {
        return Optional.ofNullable(data);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy