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]

Reply via email to