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

io.thedocs.soyuz.err.Err Maven / Gradle / Ivy

There is a newer version: 3.03
Show newest version
package io.thedocs.soyuz.err;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import javax.annotation.Nullable;
import java.util.Map;

/**
 * Created by fbelov on 31.05.16.
 */
@Getter
@EqualsAndHashCode
@ToString
public class Err {

    @Nullable
    private String field;
    private String code;
    @Nullable
    private String message;
    @Nullable
    private V value;
    @Nullable
    private Map params;

    @JsonIgnore
    public boolean isGlobalScope() {
        return field == null;
    }

    @JsonIgnore
    public boolean isFieldScope() {
        return field != null;
    }

    public static  ErrBuilder builder() {
        return new ErrBuilder<>();
    }

    private Err() {
    }

    private Err(String field, String code, String message, V value, Map params) {
        this.field = field;
        this.code = code;
        this.message = message;
        this.value = value;
        this.params = params;
    }

    public ErrBuilder toBuilder() {
        return Err.builder().field(field).code(code).message(message).value(value).params(params);
    }

    public boolean hasField() {
        return field != null;
    }

    public boolean hasMessage() {
        return message != null;
    }

    public boolean hasValue() {
        return value != null;
    }

    public boolean hasParams() {
        return params != null;
    }

    public static  ErrBuilder code(Code code) {
        return Err.builder().code(code);
    }

    public static  ErrBuilder code(String code) {
        return Err.builder().code(code);
    }

    public static  ErrBuilder field(String field) {
        return Err.builder().field(field);
    }

    public static  ErrBuilder message(String  message) {
        return Err.builder().message(message);
    }

    public interface Code {

        String getErrCode();

    }

    public static class ErrBuilder {
        private String field;
        private String code;
        private String message;
        private V value;
        private Map params;

        public Err build() {
            return new Err<>(field, code, message, value, params);
        }

        public ErrBuilder field(String field) {
            this.field = field;

            return this;
        }

        public ErrBuilder code(String code) {
            this.code = code;

            return this;
        }

        public ErrBuilder code(Code code) {
            if (code != null) {
                this.code = code.getErrCode();
            }

            return this;
        }

        public ErrBuilder message(String message) {
            this.message = message;

            return this;
        }

        public ErrBuilder value(V value) {
            this.value = value;

            return this;
        }

        public ErrBuilder params(Map params) {
            this.params = params;

            return this;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy