commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex D Herbert (JIRA)" <>
Subject [jira] [Created] (LANG-1436) Consolidate StringUtils equals and equalsIgnoreCase method
Date Sun, 03 Mar 2019 13:09:00 GMT
Alex D Herbert created LANG-1436:

             Summary: Consolidate StringUtils equals and equalsIgnoreCase method
                 Key: LANG-1436
             Project: Commons Lang
          Issue Type: Improvement
          Components: lang.*
    Affects Versions: 3.8.1
            Reporter: Alex D Herbert

The methods {{equals}} and {{equalsIgnoreCase}} in {{StringUtils}} are essentially the same
method but one is case insensitive. However the method arguments have different names, the
edge case check logic is different (with the same effect) and the javadocs are slightly different.

The {{equals}} method also calls a {{CharSequenceUtils}} helper method which is unnecessary
as that contains functionality that is not used, i.e. the case insensitivity. This can be
updated to just do a simple step-wise charAt comparison through the entire {{CharSequence}}:

final int length = cs1.length();
for (int i = 0; i < length; i++) {
    if (cs1.charAt(i) != cs2.charAt(i)) {
        return false;

The result is code that does the same as before but is cleaner to understand.

This change will consolidate the two methods to improve the similarity in both the documentation
and the implementation:

* Update the parameter names to match
* Update the Javadoc to match with the exception of case sensitivity
* Update the edge case logic to match in the implementation
* Update to use a step-wise {{charAt}} comparison

This message was sent by Atlassian JIRA

View raw message