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

com.cyngn.vertx.async.ResultContext Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
package com.cyngn.vertx.async;

/**
 * Handles wrapping what occurred as a result of an async operation.
 *
 * @author [email protected] (Jeremy Truelove) 9/3/15
 */
public class ResultContext {
    public final boolean succeeded;
    public final Throwable error;
    public final String errorMessage;
    public final T value;

    /**
     * Creates a new result context that represents an operation that completed without error.
     *
     * @param succeeded True if the operation was successful, false otherwise.
     */
    public ResultContext(boolean succeeded) {
        this.succeeded = succeeded;
        this.value = null;
        this.error = null;
        this.errorMessage = null;
    }

    /**
     * Creates a new result context that represents an operation that completed without error.
     *
     * @param succeeded True if the operation was successful, false otherwise.
     * @param value The resulting value.
     */
    public ResultContext(boolean succeeded, T value) {
        this.succeeded = succeeded;
        this.value = value;
        this.error = null;
        this.errorMessage = null;
    }

    /**
     * Creates a new result context that represents a failed async operation.
     *
     * @param error The {@link Throwable} error that was the result of the operation.
     * @param errorMessage The error message.
     */
    public ResultContext(Throwable error, String errorMessage) {
        this.succeeded = false;
        this.value = null;
        this.error = error;
        this.errorMessage = errorMessage;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy