commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael A. Smith" <...@apache.org>
Subject RE: [collection] Collections for primitives
Date Tue, 25 Jun 2002 17:50:54 GMT
On Tue, 25 Jun 2002, Jack, Paul wrote:
> > I'm still curious what the use-case is for a situation that would 
> > require non-"fail-fast" collections.  I understand the theory, I just 
> > want to hear how it would be used in practice.
> 
> A website allows a user to quickly look up their account information
> by entering their userId, which is always an Integer, and then clicking
> submit. 

ok.  

> The servlet that handles that request uses a Map that maps Integers to
> account information.

ok. I'm going to make an assumption that something would have to convert
the String provided in the request parameters to an Integer in order to
perform the lookup.


> If the user incorrectly enters their user id, the containsKey(userId) call
> returns false, regardless of whether the userId has a syntax
> error or if it doesn't exist in the map.  When it returns false, the 
> user is prompted to re-enter the information. 

In both the normal case (user enters proper user id) and the "error" 
case (user incorrectly enters their user id), the string provided by the 
request parameter is converted to an Integer (outside of teh containsKey 
method).  In the case where the user types "foo" instead of "5", that 
converstion will fail and not produce an Integer object.  That failure 
should be reported to the user before even attempting to call 
containsKey.  

If my assumption is incorrect (there is no conversion required, the 
thing just shows up as an Integer), then there shouldn't be an exception 
thrown, just a false result (i.e. no mapping with that Integer key).  

> A bit more straightforward then both checking for a false result AND
> catching an exception.

Maybe I'm still missing something, but I don't see how you could be 
passing in two different typed objects into containsKey -- one correct 
(Integer) and one incorrect without having a "bug" elsewhere in the 
application (e.g. ignoring the conversion failure).  

regards,
michael


--
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