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

cdc.issues.NameValueMap Maven / Gradle / Ivy

There is a newer version: 0.62.0
Show newest version
package cdc.issues;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface NameValueMap {
    /**
     * @return {@code true} if this map is empty.
     */
    public boolean isEmpty();

    /**
     * @return The set of names.
     */
    public Set getNames();

    /**
     * @return The sorted names.
     */
    public List getSortedNames();

    /**
     * @param name The name.
     * @return The value associated to {@code name} or {@code null}.
     */
    public String getValue(String name);

    /**
     * @param name The name.
     * @param def The default value to return.
     * @return The value associated to {@code name} or {@code def}.
     */
    public String getValue(String name,
                           String def);

    /**
     * @return A collection of {@link NameValue}.
     */
    public Collection getNameValues();

    /**
     * @return A list of {@link NameValue} sorted using their name.
     */
    public List getSortedNameValues();

    public abstract static class Builder> {
        protected Map map = new HashMap<>();

        protected Builder() {
        }

        @SuppressWarnings("unchecked")
        protected B self() {
            return (B) this;
        }

        /**
         * Adds a new (name, value) pair.
         *
         * @param name The meta name.
         * @param value The meta value.
         * @return This builder.
         * @throws IllegalArgumentException When {@code name} is not valid.
         */
        public B entry(String name,
                       String value) {
            map.put(name, value);
            return self();
        }

        public B entries(Collection entries) {
            for (final NameValue entry : entries) {
                map.put(entry.getName(), entry.getValue());
            }
            return self();
        }

        public B entries(NameValueMap other) {
            for (final String name : other.getNames()) {
                map.put(name, other.getValue(name));
            }
            return self();
        }

        public abstract M build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy