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

cdc.applic.dictionaries.edit.EnSynonyms Maven / Gradle / Ivy

There is a newer version: 0.13.3
Show newest version
package cdc.applic.dictionaries.edit;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import cdc.util.lang.Checks;

public final class EnSynonyms {
    private final EnAbstractElement owner;
    private final Map, String> map = new HashMap<>();

    protected EnSynonyms(EnAbstractElement owner,
                         Map synonyms) {
        this.owner = Checks.isNotNull(owner, EnNames.OWNER);
        for (final Map.Entry entry : synonyms.entrySet()) {
            // Do not call set() to avoid firing change events
            map.put(EnRef.of(owner, EnNamingConvention.class, entry.getKey()),
                    entry.getValue());
        }
    }

    public EnAbstractElement getOwner() {
        return owner;
    }

    public boolean isEmpty() {
        return map.isEmpty();
    }

    public void set(EnNamingConvention convention,
                    String synonym) {
        map.put(EnRef.of(owner, EnNamingConvention.class, convention),
                synonym);
        owner.fireSemanticChange(EnNames.SYNONYMS);
    }

    public void set(String conventionId,
                    String synonym) {
        map.put(EnRef.of(owner, EnNamingConvention.class, conventionId),
                synonym);
        owner.fireSemanticChange(EnNames.SYNONYMS);
    }

    public void remove(EnRef conventionRef) {
        map.remove(conventionRef);
        owner.fireSemanticChange(EnNames.SYNONYMS);
    }

    public Set getSynonyms() {
        return new HashSet<>(map.values());
    }

    public Set getRefAndSynonyms(String ref) {
        final Set set = new HashSet<>(map.values());
        set.add(ref);
        return set;
    }

    public Set> getNamingConventionRefs() {
        return map.keySet();
    }

    public String getSynonym(EnRef conventionRef) {
        return map.get(conventionRef);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy