cn.cheny.toolbox.other.ResultAndFlag Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolbox Show documentation
Show all versions of toolbox Show documentation
A personal java tool package project
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