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

org.opentripplanner.netex.loader.util.HierarchicalMap Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.netex.loader.util;

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

/**
 * A concrete implementation of {@link AbstractHierarchicalMap}.
 *
 * @param  the key type
 * @param  the value type
 */
public class HierarchicalMap extends AbstractHierarchicalMap {
    private Map map  = new HashMap<>();

    /** Create a new hierarchical map root. */
    public HierarchicalMap() {
        super(null);
    }

    /** Create new child map with the given {@code parent}. */
    public HierarchicalMap(HierarchicalMap parent) {
        super(parent);
    }

    /**
     * Add a new pair of {@code key & value} to the local map instance.
     */
    public void add(K key, V value) {
        map.put(key, value);
    }

    /**
     * Add a set of {@code keys & values} to the local map instance.
     */
    public void addAll(Map other) {
        for (Map.Entry e : other.entrySet()) {
            add(e.getKey(), e.getValue());
        }
    }

    /** @return return all keys in the local map */
    Set localKeys() {
        return map.keySet();
    }

    /**
     * @return a collection of all values hold in the local map, all values added to one of the
     * parents are excluded from the collection.
     */
    Collection localValues() {
        return map.values();
    }

    @Override
    V localGet(K key) {
        return map.get(key);
    }

    @Override
    boolean localContainsKey(K key) {
        return map.containsKey(key);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy