ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject RE: Looking for map with collection values with contains method a t map level
Date Mon, 16 Sep 2002 16:57:34 GMT
That's awful in terms of efficiency, especially if the collections
themselves are not hashed. I cannot imagine what you would use that for...

If all you care about is to know fast if any collection in your map contains
an entry, then keep an HashSet of all the collections values
(set.addAll(collection)), and query that hashset. Note what you wanted to
hear ?!?! ;-) --DD

-----Original Message-----
From: [] 
Sent: Monday, September 16, 2002 11:18 AM
To: Ant Developers List
Subject: Re: Looking for map with collection values with contains method at
map level

I messed up the example.  It should read:
FancyMap fm = new FancyMap();

Collection col1 = new ArrayList();

Collection col2 = new ArrayList();

fm.put("key1", col1);
fm.put("key2", col2);

boolean wordFound = fm.anyCollectionContains("jimmy");

An implementation I quickly made as an inner class is:

      private class CollectionMap extends HashMap {
            public CollectionMap() {
            public boolean anyCollectionContains(Object o1) {
                  boolean objectFound = false;

                  Collection values = this.values();
                  Iterator iter = values.iterator();
                  while (iter.hasNext()) {
                        Collection value = (Collection);
                        if (value.contains(o1)) {
                              objectFound = true;

                  return objectFound;

I was simply hoping to find something as part of a popular library,
preferably ant or commons related.

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

View raw message