[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [really patch] Re: HashMap putAll/putAllInternal bug

From: David Holmes
Subject: RE: [really patch] Re: HashMap putAll/putAllInternal bug
Date: Mon, 13 Oct 2003 09:08:14 +1000

Stuart Ballard wrote:
> My requirement is for a map which holds references to two
> other maps, "front" and "back". The keySet() of my map is the union
> front.keySet() and back.keySet(). The value corresponding
> to a given key is 'front.containsKey(key) ? front.get(key) :
> back.get(key)'. Both front and back can be accessed directly through
> other code and may change in any way without my map being notified.
> How can I implement size() without a full iteration?

If you extend AbstractMap (why on earth would you with this
specialised implementation?) then size is defined as
entrySet().size(). From what you wrote it would appear that
entrySet().size() in your case will be a function of the size of the
front and back entrysets. Even if these are modified outside of the
main map, as long as it's not concurrent (in which case you're on your
own), then you should still be able to calculate the map size if the
front and back maps maintain their size correctly.

If you can't provide a valid implementation for any concrete method
that you are supposed to implement, then it seems quite unreasonable
of you to expect any inherited methods to work for you. I think it
quite reasonable for a method like putAll to expect to be able to use
any of the non-optional methods of Map/Set/Iterator to do its job -
even if it doesn't document exactly which methods it uses.

David Holmes

reply via email to

[Prev in Thread] Current Thread [Next in Thread]