org.opentripplanner.netex.index.hierarchy.HierarchicalMap Maven / Gradle / Ivy
package org.opentripplanner.netex.index.hierarchy;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* A concrete implementation of {@link AbstractHierarchicalMap}.
*
* @param the key type
* @param the value type
*/
public class HierarchicalMap extends AbstractHierarchicalMap {
private final 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);
}
/** Return a reference to the parent. */
public HierarchicalMap parent() {
return (HierarchicalMap) 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 */
public Collection 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.
*/
public Collection localValues() {
return map.values();
}
@Override
V localGet(K key) {
return map.get(key);
}
@Override
boolean localContainsKey(K key) {
return map.containsKey(key);
}
@Override
protected int localSize() {
return map.size();
}
@Override
void localRemove(K key) {
map.remove(key);
}
}