You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Janek Bogucki <ya...@studylink.com> on 2003/09/07 03:35:41 UTC
[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?
Re: [collections] CollectionUtils.getCardinalityMap JavaDoc
Posted by Stephen Colebourne <sc...@btopenworld.com>.
Your logic makes sense to me ;-)
Stephen
----- Original Message -----
From: "Janek Bogucki" <ya...@studylink.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Sunday, September 07, 2003 2:35 AM
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 {@link Map} mapping each unique element in
> * the given {@link Collection} to an {@link Integer}
> * representing the number of occurences of that element
> * in the {@link Collection}.
> * An entry that maps to <tt>null</tt> indicates that the
> * element does not appear in the given {@link 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: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>