Hello,

‘MapStack’ is a specialization of the ‘MapContext’ class which is an
implementation of ‘Map’ interface that has the particularity to store
its key-values in separate sub-maps that can mask each others.

The whole point of ‘MapStack’ implementation is to override the Map
accessors to ensure that the key "context" is associated with ‘this’
meaning the ‘MapStack’ instance.

--8<---------------cut here---------------start------------->8---
    @Override
    public Object get(Object key) {
        if ("context".equals(key)) {
            return this;
        }
        return super.get(key);
    }

    @Override
    public Object get(String name, Locale locale) {
        if ("context".equals(name)) {
            return this;
        }
        return super.get(name, locale);
    }

    @Override
    public Object put(K key, Object value) {
        if ("context".equals(key)) {
            if (value == null || this != value) {
                Debug.logWarning("Putting a value in a MapStack with key 
[context] that is not this MapStack, will be hidden by the current MapStack 
self-reference: " + value, module);
            }
        }
        return super.put(key, value);
    }
--8<---------------cut here---------------end--------------->8---

I don't understand the purpose of such thing.  So if someone has some
rationale to share, I would be grateful.

Thanks.

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37

Reply via email to