123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- package com.boman.system.common;
- import com.alibaba.fastjson.JSONObject;
- import lombok.Data;
- import java.io.Serializable;
- /**
- * @author shiqian
- * @description
- * @date 2021年03月22日 09:26
- **/
- @Data
- public class ValueHolder<T> implements Serializable {
- public static final int OK = 0;
- public static final int FAIL = -1;
- private T data;
- private int code;
- private String message;
- public ValueHolder() {
- }
- public ValueHolder(int code, String message, T data) {
- this.data = data;
- this.code = code;
- this.message = message;
- }
- public ValueHolder(int code, String message) {
- this.code = code;
- this.message = message;
- }
- public JSONObject toJSONObject() {
- JSONObject obj = new JSONObject();
- obj.put("code", this.code);
- obj.put("message", this.message);
- obj.put("data", this.data);
- return obj;
- }
- public static <T> ValueHolder<T> ok(String message){
- return new ValueHolder<>(OK, message);
- }
- public static <T> ValueHolder<T> ok(String message, T data){
- return new ValueHolder<>(OK, message, data);
- }
- public static <T> ValueHolder<T> ok(T data){
- return new ValueHolder<>(OK, "成功", data);
- }
- public static <T> ValueHolder<T> fail(String message, T data){
- return new ValueHolder<>(FAIL, message, data);
- }
- public static <T> ValueHolder<T> fail(String message){
- return new ValueHolder<>(FAIL, message);
- }
- public boolean isOK() {
- return this.code == 0;
- }
- public String toDebugString() {
- return this.toJSONObject().toString();
- }
- public T getData() {
- return this.data;
- }
- public int getCode() {
- return this.code;
- }
- public String getMessage() {
- return this.message;
- }
- public void setData(final T data) {
- this.data = data;
- }
- public void setCode(final int code) {
- this.code = code;
- }
- public void setMessage(final String message) {
- this.message = message;
- }
- @Override
- public boolean equals(final Object o) {
- if (o == this) {
- return true;
- } else if (!(o instanceof ValueHolder)) {
- return false;
- } else {
- ValueHolder<?> other = (ValueHolder)o;
- if (!other.canEqual(this)) {
- return false;
- } else {
- label39: {
- Object this$data = this.getData();
- Object other$data = other.getData();
- if (this$data == null) {
- if (other$data == null) {
- break label39;
- }
- } else if (this$data.equals(other$data)) {
- break label39;
- }
- return false;
- }
- if (this.getCode() != other.getCode()) {
- return false;
- } else {
- Object this$message = this.getMessage();
- Object other$message = other.getMessage();
- if (this$message == null) {
- return other$message == null;
- } else return this$message.equals(other$message);
- }
- }
- }
- }
- protected boolean canEqual(final Object other) {
- return other instanceof ValueHolder;
- }
- @Override
- public int hashCode() {
- int result = 1;
- Object $data = this.getData();
- result = result * 59 + ($data == null ? 43 : $data.hashCode());
- result = result * 59 + this.getCode();
- Object $message = this.getMessage();
- result = result * 59 + ($message == null ? 43 : $message.hashCode());
- return result;
- }
- @Override
- public String toString() {
- return "ValueHolder(data=" + this.getData() + ", code=" + this.getCode() + ", message=" + this.getMessage() + ")";
- }
- }
|