class ScopedMap implements ScopeSubscriber, Map<K, V> {

    public V put(final K key, final V value) {
        Stack<ScopedMapItem<V>> stack = map.get(key);
        ScopedMapItem<V> previousItem;

        if (stack == null) {
            stack = new Stack<ScopedMapItem<V>>();

            map.put(key, stack);

            previousItem = null;
        } else {
            if (stack.empty()) {
                previousItem = null;
            } else {
                previousItem = stack.peek();
            }
        }

        final ScopedMapItem<V> item = new ScopedMapItem<V>(scope, value);
        stack.push(item);

        if (previousItem == null) {
            return null;
        }

        return previousItem.getValue();
    }

    public  ScopedMap(final ScopeObserver scopeObserver);

}