java系统内部 返回结果封装类

public class BaseResponse implements Serializable {
    public static int RESP_CODE_OK = 200;
    protected boolean success;
    protected int code;
    protected String msg;
    protected String redirectUrl;

    public BaseResponse() {
    }

    public BaseResponse(boolean success, int code, String msg) {
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public BaseResponse(boolean success, int code, String msg, String redirectUrl) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.msg = redirectUrl;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public String getRedirectUrl() {
        return this.redirectUrl;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setRedirectUrl(String redirectUrl) {
        this.redirectUrl = redirectUrl;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof BaseResponse)) {
            return false;
        } else {
            BaseResponse other = (BaseResponse)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.isSuccess() != other.isSuccess()) {
                return false;
            } else if (this.getCode() != other.getCode()) {
                return false;
            } else {
                label40: {
                    Object this$msg = this.getMsg();
                    Object other$msg = other.getMsg();
                    if (this$msg == null) {
                        if (other$msg == null) {
                            break label40;
                        }
                    } else if (this$msg.equals(other$msg)) {
                        break label40;
                    }

                    return false;
                }

                Object this$redirectUrl = this.getRedirectUrl();
                Object other$redirectUrl = other.getRedirectUrl();
                if (this$redirectUrl == null) {
                    if (other$redirectUrl != null) {
                        return false;
                    }
                } else if (!this$redirectUrl.equals(other$redirectUrl)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof BaseResponse;
    }

    public int hashCode() {
        int result = 1;
        result = result * 59 + (this.isSuccess() ? 79 : 97);
        result = result * 59 + this.getCode();
        Object $msg = this.getMsg();
        result = result * 59 + ($msg == null ? 43 : $msg.hashCode());
        Object $redirectUrl = this.getRedirectUrl();
        result = result * 59 + ($redirectUrl == null ? 43 : $redirectUrl.hashCode());
        return result;
    }

    public String toString() {
        return "BaseResponse(success=" + this.isSuccess() + ", code=" + this.getCode() + ", msg=" + this.getMsg() + ", redirectUrl=" + this.getRedirectUrl() + ")";
    }
}
public class Response<T> extends BaseResponse {
    private T data;

    public Response(Boolean success, int code, String msg) {
        super(success, code, msg);
        this.data = null;
    }

    public Response(Boolean success, T result, int code, String msg) {
        super(success, code, msg);
        this.data = result;
    }

    public Response() {
    }

    public static <T> Response<T> ok() {
        return new Response(true, RESP_CODE_OK, (String) null);
    }

    public static <T> Response<T> ok(T result) {
        return new Response(true, result, RESP_CODE_OK, (String) null);
    }

    public static <T> Response<T> fail(int code, String respMsg) {
        return new Response(false, code, respMsg);
    }

    public static <T> Response<T> fail(int code, String msg, Throwable e) {
        return new Response(false, code, msg);
    }

    public static <T> Response<T> fail(int code, String msgFormat, Object... args) {
        return new Response(false, code, String.format(msgFormat, args));
    }

    public static <T> Response<T> fail(String msg) {
        return fail(-1, msg);
    }

    public boolean isOk() {
        return this.success;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Response)) {
            return false;
        } else {
            Response<?> other = (Response) o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Response;
    }

    public int hashCode() {
        int result = 1;
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    public String toString() {
        return "Response(data=" + this.getData() + ")";
    }
}
上一篇:Linux SCHED_FIFO, SCHED_RR和SCHED_OTHER


下一篇:四、数据类型_6.(4).set - set运算