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

com.scloudic.rabbitframework.web.Result Maven / Gradle / Ivy

There is a newer version: 4.0.7
Show newest version
package com.scloudic.rabbitframework.web;

import com.scloudic.rabbitframework.core.utils.StatusCode;
import com.scloudic.rabbitframework.web.utils.ServletContextHelper;

public class Result {
    private String message;
    private T data;
    private int status;

    public Result(String message, int status, T data) {
        this.message = message;
        this.status = status;
        this.data = data;
    }

    public static  Result success(String message, T data) {
        return new Result(message, StatusCode.SC_OK.getValue(), data);
    }

    public static  Result success(T data) {
        return success(ServletContextHelper.getMessage("success"), data);
    }

    public static  Result success() {
        return success(ServletContextHelper.getMessage("success"), null);
    }

    public static  Result failure(StatusCode statusCode, String message) {
        return new Result(message, statusCode.getValue(), null);
    }

    public static  Result failure(int status, String message, T data) {
        return new Result(message, status, data);
    }

    public static  Result failure(StatusCode statusCode, String message, T data) {
        return failure(statusCode.getValue(), message, data);
    }

    public static  Result failure(int status, String message) {
        return failure(status, message, null);
    }

    public static  Result failure(StatusCode statusCode) {
        return new Result(statusCode.getMsg(), statusCode.getValue(), null);
    }

    public static  Result failure(String message) {
        return new Result(message, StatusCode.FAIL.getValue(), null);
    }

    public static  Result failure(int status) {
        return new Result(ServletContextHelper.getMessage("fail"), status, null);
    }

    public static  Result failure() {
        return failure(ServletContextHelper.getMessage("fail"));
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

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

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy