commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack, Paul" <pj...@sfaf.org>
Subject RE: [Collections][SUBMIT] TypedList
Date Tue, 30 Apr 2002 17:02:22 GMT
Hi Michal,

In another thread ([SUBMIT] WeakHashSet) we've been discussing
having a two-transformer based approach that would let you handle
strings in the way you describe.  The functionality we were
trying to achieve was the ability for a list or set or map to
transform objects into WeakReferences before adding them to the
collection and transforming the WeakReferences back into their
referents before returning them from the collection...the same
pattern could be used for case-insensitive strings with a class
like this:

   public class CaseInsensitiveString {

       String string;

       public CaseInsensitiveString(String string) {
            this.string = string;
       }

       public boolean equals(Object o) {
           return string.equalsIgnoreCase(o);
       }

       public int hashCode() {
           return string.hashCode();
       }
   }

The input transformer could convert the normal string to a 
CaseInsensitiveString, and the output transformer could convert
the CaseInsensitiveString back into a normal string.

You might want to check out the WeakHashSet thread to see if 
you think this approach makes sense...

-Paul


-----Original Message-----
From: Michal Plechawski [mailto:Michal.Plechawski@empolis.pl]
Sent: Tuesday, April 30, 2002 8:35 AM
To: Jakarta Commons Developers List
Subject: Re: [Collections][SUBMIT] TypedList


Hello,

> Just being Devil's advocate for a moment but....
> Couldn't this kind of thing be done with custom Comparators and (say)
> TreeMap?

Of course it could. But everyone knows that HashMap is much more efficient
than TreeMap, and so is the wrapper I described. This allows not to be
constrained to particular Map implementation.
Another thing is that I do not understand the real use case laying behind
the discussed Transform-xxx. I do not see why somebody wants to put
transformed elements into a collection, but ask for them directly. It breaks
some natural laws, like:

map.put(x, y);
map.containsKey(x); // this should be true

I think that this may be very misleading for many people, and be the reason
of hard-to-find errors. IMHO this idea breaks basic Collection Framework
intuitions.

However, this Predicate-xxx stuff is a completely different story and a good
idea I think.

Regards,
Michal



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

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


Mime
View raw message