On 2011-01-08, at 09:58, André Bargull wrote:

> 
> 
> On 1/8/2011 3:23 PM, P T Withington wrote:
>> On 2011-01-08, at 08:23, André Bargull wrote:
>> 
>>> This also appears to fix LPP-7278.
>> 
>> Gee, I really ought to pay more attention to the bugs you file!  Can't 
>> believe I missed that...
> 
> A possible New Year resolution for 2011?! :-)

Hm...

>>> Parent model fallbacks supersede current model's fallbacks, etc.?
>>>> +    if (parentNodeModel != null) {
>>>> +      
>>>> CSSAttributeProperties.putAll(parentNodeModel.CSSAttributeProperties);
>>>> +      CSSAttributeTypes.putAll(parentNodeModel.CSSAttributeTypes);
>>>> +      CSSAttributeFallbacks.putAll(parentNodeModel.CSSAttributeFallbacks);
>>>> +    }
>>> same here...
>>>> +    if (parentNodeModel != null) {
>>>> +      CSSPropertyExpanders.putAll(parentNodeModel.CSSPropertyExpanders);
>>>> +      
>>>> CSSPropertyInheritable.putAll(parentNodeModel.CSSPropertyInheritable);
>>>> +    }
>> 
>> Thanks!  Brain-oh on my part.  I want set union, but not to replace existing 
>> entries.  I guess I need to use something like:
>> 
>>   private void inherit(HashMap child, HashMap parent) {
>>     Set missing = parent.keySet();
>>     // Wow Java, you suck.  Wouldn't it make more sense to return the
>>     // set than a boolean?
>>     missing.removeAll(child.keySet());
>>     for (Iterator i = missing.iterator(); i.hasNext();) {
>>       String key = (String)i.next();
>>       child.put(key, parent.get(key));
>>     }
>>   }
>> 
>> Unless you know of a primitive operation on Map that does that?
> 
> You better don't do it that way, because the key-set is mapped to the 
> original map, so changes in the key-set are reflected to the map (and 
> vice-versa). So you either need to iterate over the keySet() (or entrySet() 
> like below) or copy the parent map, remove all keys from the copy which are 
> already included in the child and then add the copy to the child.

Holy smokes.  More non-intuitive features of Java Maps.  Perhaps I should 
actually read the documentation.  Wait, you will tell me _that_ should be a New 
Year's resolution too?

>> private void inherit (Map child, Map parent) {
>>    for (Iterator itr = parent.entrySet().iterator(); itr.hasNext(); ) {
>>        Map.Entry entry = (Map.Entry) itr.next();
>>        if (! child.containsKey(entry.getKey())) {
>>            child.put(entry.getKey(), entry.getValue());
>>        }
>>    }
>> }

Simple is always the best.  Thank you!


Reply via email to