commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Moritz Petersen <>
Subject Re: [PATCH] [collections] new: MapUtils#asMap(Object[]) and MapUtils#toMapEntry(Object)
Date Sat, 12 Oct 2002 21:08:52 GMT
Sorry, that I forgot to send the test case together with the first 
mail. A typical newbie mistake, I guess.

Ok, some explanations to the patch:

I first realized the most simple method of all: asMap(Object[]). This 
method just creates a new Map and returns it. By using the 
toMapEntry(Object) method, it is possible to do it with almost no 
Now my ignorance takes control, because I still don't understand the 
difference in semantics between to... and as...

to... wraps and as... initializes a new object. Good.

But what is the _use_ of to...? (There will some useful pages in the 
web, explaining this topic, I guess. Links are appreciated.).

If I implement the toMap(Object[]) method, I need a wrapper class that 
implements the Map interface and is backed up by the given Object[] 
array. The problem for me is, that the use of it will be very 
expensive. So, why not just create a new object using asMap()?

To summarize the pros and cons:

asMap                | toMap
creates a new        | creates a new
instance             | instance of a
                      | wrapper class
populates the new    | accesses the backing
instance in the      | array only on demand
moment it is created |

If I am not wrong, the advantage of the to... methods is, that the 
wrapper class is backed up by the array, and will access its elements 
only on demand.(?)

Another word about the toMapEntry() method. Maybe it should be renamed 
to asMapEntry(). The reason why it is called toMapEntry() is, that I in 
fact created a wrapper class, that implemented the Map.Entry interface. 
But then I realized, that there is already a DefaultMapEntry class, 
which I could use. So I exchanged my anonymous inner class with the 


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message