james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rollo, Dan" <dro...@ets.org>
Subject RE: String.equalsIgnoreCase Considered Evil :-)
Date Mon, 05 Aug 2002 14:21:52 GMT
Just read the subsequent posts on the "comand object", and that's way
better...

-----Original Message-----
From: Rollo, Dan 
Sent: Monday, August 05, 2002 10:13 AM
To: 'James Developers List'
Subject: RE: String.equalsIgnoreCase Considered Evil :-)


Isn't it safer to do:

String command = commandRaw.trim().toUpperCase();
if ("USER".equals(command)) ...

This way, you avoid NullPointerExceptions if "command" is null.
Also, shouldn't any repeated literals be declared as constants, ie:
CmdConst.USER or something similar?

Dan

-----Original Message-----
From: Noel J. Bergman [mailto:noel@devtech.com]
Sent: Saturday, August 03, 2002 11:59 PM
To: James-Dev Mailing List
Subject: String.equalsIgnoreCase Considered Evil :-)


There are many places in James where we have lengthy sets of comparisons of
an unknown string value to a known string value.  These are many of these of
the form:

	string.equalsIgnoreCase(<literal>)

This use is terribly inefficient.  Each and every call iterates through both
the string and the literal, uppercasing both as it compares them.

Please, as you are working on code (Peter will apply these to POP3Handler
and SMTPHandler), if you see this pattern, please change it to:

	string = string.to[Upper|Lower]Case();  // chose depending upon your
literals

	string.equals(<literal>)

For example, in SMTPHandler and POP3Handler:

      String command = commandRaw.trim();
 becomes
	String command = commandRaw.trim().toUpperCase();

and the test for "USER" (for example) becomes:

        if (command.equals("USER")) ...

Actually, I believe that we should add a command-map model to the handlers,
but that's a seperate issue for a separate thread.  The change proposed in
this e-mail is simple.

	--- Noel

P.S.  Brownie points for whomever recognizes the origin of the subject
header


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



************************************************************************** 
This e-mail and any files transmitted with it may contain privileged or 
confidential information. It is solely for use by the individual for whom 
it is intended, even if addressed incorrectly. If you received this e-mail 
in error, please notify the sender; do not disclose, copy, distribute, or 
take any action in reliance on the contents of this information; and delete 
it from your system. Any other use of this e-mail is prohibited. Thank you 
for your compliance.




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



************************************************************************** 
This e-mail and any files transmitted with it may contain privileged or 
confidential information. It is solely for use by the individual for whom 
it is intended, even if addressed incorrectly. If you received this e-mail 
in error, please notify the sender; do not disclose, copy, distribute, or 
take any action in reliance on the contents of this information; and delete 
it from your system. Any other use of this e-mail is prohibited. Thank you 
for your compliance.




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


Mime
View raw message