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

cn.cheny.toolbox.other.ResultAndFlag Maven / Gradle / Ivy

There is a newer version: 2.3.6-jdk8
Show newest version
package cn.cheny.toolbox.other;

import java.util.function.Consumer;

/**
 * @author cheney
 * @date 2019-07-03
 */
public class ResultAndFlag {

    private T result;

    private boolean flag;

    private String msg;

    public ResultAndFlag(T result, boolean flag, String msg) {
        this.result = result;
        this.flag = flag;
        this.msg = msg;
    }

    public ResultAndFlag(T result, boolean flag) {
        this.result = result;
        this.flag = flag;
    }

    public static  ResultAndFlag success(T result) {
        return new ResultAndFlag<>(result, true, null);
    }

    public static  ResultAndFlag fail() {
        return new ResultAndFlag<>(null, false, null);
    }

    public static  ResultAndFlag fail(T data) {
        return new ResultAndFlag<>(data, false, null);
    }

    public static  ResultAndFlag fail(String msg, T data) {
        return new ResultAndFlag<>(data, false, msg);
    }

    public T getResult() {
        return result;
    }

    public boolean isSuccess() {
        return flag;
    }

    public String getMsg() {
        return msg;
    }

    public void ifSuccess(Consumer consumer) {
        if (flag) {
            consumer.accept(result);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy