commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <>
Subject [jira] Commented: (LANG-316) Enable CaseInsensitivity in EqualsBuilder and HashCodeBuilder
Date Wed, 16 Dec 2009 05:56:18 GMT


Henri Yandell commented on LANG-316:

I changed the EqualsBuilder method to rely on String.equalsIgnoreCase. 

Given the algorithm for equalsIgnoreCase, namely:

lhs == rhs || lhs.toLowerCase().equals(rhs.toLowerCase()) || lhs.toUpperCase().equals(rhs.toUpperCase())

I'm not convinced that we can have such a thing for HashCodeBuilder. We don't know if we should
be using lowerCase or upperCase. That then leads to the issue of two objects that are considered
equal, yet have different hashcodes. 

Paul also asks in LANG-447 for:

  StringUtils.compareToIgnoreCase(s1, s2);
  CompareToBuilder.appendIgnoreCase(s1, s2);

The former is probably doable:

  isEqualIgnoreCase == true; return 0
  otherwise return compareTo on the two Strings.

I'm not entirely convinced though - should the compareTo be looking at lowercase and uppercase
- is it possible for two strings to have uppercase returning +1 and lowercase returning -1?
Probably not an example out there but might not be something we can guarantee.

The latter method suffers from the issue with HashCodeBuilder. The three builders need to
be in sync, and while CompareToBuilder could easily sit on top of StringUtils.compareToIgnoreCase
(if we can implement that), HashCodeBuilder would be unable to match it.

I'm leaning towards WONTFIX here. 

> Enable CaseInsensitivity in EqualsBuilder and HashCodeBuilder
> -------------------------------------------------------------
>                 Key: LANG-316
>                 URL:
>             Project: Commons Lang
>          Issue Type: New Feature
>    Affects Versions: 2.3
>         Environment: Any
>            Reporter: Nelson Carpentier
>            Priority: Minor
>             Fix For: 3.0
>         Attachments: lang_20070206.diff, lang_20070529.diff
> Sometimes I want a String property containing "ThisString" to be seen as equal to "THISstring".
 EqualsBuilder (and HashCodeBuilder) should be enhanced to optionally handle this requirement.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message