ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlcarpen...@household.com
Subject RE: Looking for map with collection values with contains method a t map level
Date Mon, 16 Sep 2002 23:27:48 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...
Your right, its awful.  Keeping a HashSet around with all the collection
values is a much better idea.  I had this in mind when I wrote my version.
The problem is I wanted to keep the Map interface but didn't want to
implement all the code necessary to catch every time something is added to
the Map.  Iterating over all the Map contents is slow, but simple.  It is
because my approach is slow and there are obviously better ways requiring
more implementation time, that I was hoping to find an existing library.


James Lee Carpenter
Software Engineer
Household Technical Services
6602 Convoy Court
San Diego, CA 92111

ph: 858-609-2461
email: jlcarpenter@household.com


                                                                                         
                                        
                                                                                         
                                        
                           Dominique Devienne          To:     "'Ant Developers List'" <ant-dev@jakarta.apache.org>
              
                           <DDevienne@lgc.com>         cc:                         
                                              
                                                       Subject:       RE: Looking for map
with collection values with contains    
                           09/16/2002 09:57 AM                 method a     t map level  
                                        
                           Please respond to                                             
                                        
                           "Ant Developers List"                                         
                                        
                                                                                         
                                        
                                                                                         
                                        



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: jlcarpenter@household.com [mailto:jlcarpenter@household.com]
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:
========================================
//Example
FancyMap fm = new FancyMap();

Collection col1 = new ArrayList();
col1.add("jimmy");
col1.add("was");
col1.add("here");

Collection col2 = new ArrayList();
col2.add("gonzo's");
col2.add("big"):
col2.add("nose");

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() {
                  super();
            }
            public boolean anyCollectionContains(Object o1) {
                  boolean objectFound = false;

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

                  return objectFound;
            }
      }

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

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>







--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message