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

org.bidib.wizard.api.model.Flag Maven / Gradle / Ivy

There is a newer version: 2.0.29
Show newest version
package org.bidib.wizard.api.model;

import org.apache.commons.lang3.StringUtils;

public class Flag implements IdAware {

    private int id;

    private String label;
    
    public static final Flag NONE = new Flag.Builder(-1).build();

    public Flag() {
    }

    public Flag(int id) {
        this(id, null);
    }

    public Flag(int id, String label) {
        this.id = id;
        this.label = label;
    }

    private Flag(Builder builder) {
        setId(builder.id);
        setLabel(builder.label);
    }

    @Override
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Flag) {
            Flag other = (Flag) obj;
            if (id == other.id) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        return id;
    }

    public String toString() {
        String result = null;

        if (!StringUtils.isBlank(label)) {
            result = label;
        }
        // else {
        // result = Resources.getString(getClass(), "label") + "_" + id;
        // }
        return result;
    }
    
    public static class Builder {
        private final int id;

        private String label;

        public Builder(int id) {
            this.id = id;
        }

        public Builder setLabel(String label) {
            this.label = label;
            return this;
        }

        public Flag build() {
            return new Flag(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy