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

fun.bigtable.kraken.bean.Result Maven / Gradle / Ivy

There is a newer version: 2.0.9.1
Show newest version
package fun.bigtable.kraken.bean;

import fun.bigtable.kraken.constant.ResponseState;
import fun.bigtable.kraken.exception.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Optional;

public class Result {
    private T body;
    private String state;
    private String errCode;
    private String errMsg;
    private List privacy;

    private static final Logger LOGGER = LoggerFactory.getLogger(Result.class);

    private Result(ResponseState responseState, T object) {
        this.state = responseState.getState();
        if (object != null) {
            this.body = object;
        }
    }

    public Result() {
    }

    private Result(ResponseState responseState, String errCode, String errMsg) {
        this.state = responseState.getState();
        if (errCode != null) {
            this.errCode = errCode;
        }
        if (errMsg != null) {
            this.errMsg = errMsg;
        }
    }

    public String getErrCode() {
        return errCode;
    }


    public T getBody() {
        return body;
    }


    public String getState() {
        return state;
    }


    public String getErrMsg() {
        return errMsg;
    }


    public List getPrivacy() {
        return privacy;
    }

    public void setPrivacy(List privacy) {
        this.privacy = privacy;
    }

    public static  Result success() {
        return new Result<>(ResponseState.SUCCESS, null);
    }

    public static  Result success(T object) {
        return new Result<>(ResponseState.SUCCESS, object);
    }

    public static  Result fail(Type type) {
        return new Result<>(ResponseState.FAIL, type.getErrorCode(), type.getErrorCode());
    }

    public static  Result fail(Type type, String err) {
        return new Result<>(ResponseState.FAIL, type.getErrorCode(), Optional.ofNullable(err).orElse(type.getDesc()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy