I'm not sure if it makes sense to call it an "entry that maps to null" but consider 
that the the cardinal map returned by this function will be accessed in the following 
manner:

 Integer x = returnedMap.get(obj);

That statement may just be pointing out that instead of returning Integer(0) for 
objects that weren't in the collection, a null will be returned instead - as you 
pointed out, an object not in the collection will not be mapped to anything, and so, 
when used as a key, will lead to a null value.  

Perhaps the doc could be clarified.  

-AMT

-----Original Message-----
From: Janek Bogucki [mailto:[EMAIL PROTECTED] 
Sent: Saturday, September 06, 2003 6:36 PM
To: Jakarta Commons Developers List
Subject: [collections] CollectionUtils.getCardinalityMap JavaDoc


In CollectionUtils.getCardinalityMap the documentation notes the meaning of an entry 
that maps to null but I don't see how any such entry can exist in the returned map as 
all the keys in the map come from the collection parameter and will map to >=1. Have I 
missed something?

>From CollectionUtils v 1.36
 
    /**
     * Returns a [EMAIL PROTECTED] Map} mapping each unique element in
     * the given [EMAIL PROTECTED] Collection} to an [EMAIL PROTECTED] Integer}
     * representing the number of occurences of that element
     * in the [EMAIL PROTECTED] Collection}.
     * An entry that maps to <tt>null</tt> indicates that the
     * element does not appear in the given [EMAIL PROTECTED] Collection}.
     */
    public static Map getCardinalityMap(final Collection col) {
        HashMap count = new HashMap();
        Iterator it = col.iterator();
        while(it.hasNext()) {
            Object obj = it.next();
            Integer c = (Integer)(count.get(obj));
            if(null == c) {
                count.put(obj,new Integer(1));
            } else {
                count.put(obj,new Integer(c.intValue() + 1));
            }
        }
        return count;
    }


-Janek

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to