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

liquibase.Labels Maven / Gradle / Ivy

There is a newer version: 3.6.2.5.inovus
Show newest version
package liquibase;

import liquibase.util.StringUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

public class Labels {

    private Set labels = new LinkedHashSet<>();

    public Labels() {
    }

    public Labels(String... labels) {
        if (labels.length == 1) {
            parseLabelString(labels[0]);
        } else {
            for (String label : labels) {
                this.labels.add(label.toLowerCase());
            }
        }
    }

    public Labels(String labels) {
        parseLabelString(labels);
    }

    private void parseLabelString(String labels) {
        labels = StringUtils.trimToNull(labels);

        if (labels == null) {
            return;
        }
        for (String label : StringUtils.splitAndTrim(labels, ",")) {
            this.labels.add(label.toLowerCase());
        }

    }

    public Labels(Collection labels) {
        if (labels != null) {
            for (String label : labels) {
                this.labels.add(label.toLowerCase());
            }

        }
    }

    public boolean add(String label) {
        return this.labels.add(label.toLowerCase());
    }

    public boolean remove(String label) {
      return this.labels.remove(label.toLowerCase());
    }

    @Override
    public String toString() {
        return StringUtils.join(new LinkedHashSet<>(this.labels),",");
    }

    public boolean isEmpty() {
        return (this.labels == null) || this.labels.isEmpty();
    }

    public Set getLabels() {
        return Collections.unmodifiableSet(labels);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy