[ 
https://issues.apache.org/jira/browse/LANG-1030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14068489#comment-14068489
 ] 

Michael Bazos commented on LANG-1030:
-------------------------------------

I don't think getCommonPrefix is what I am looking for.  Basically this method 
would act the same as equalsIgnoreCase but instead of returning a boolean it 
would return a new string representation of str1.  This is really a connivence 
method to save a couple lines of code but I figured this would be the 
appropriate place to ask the question.

getCommonPrefix does the following:
{code}
 StringUtils.getCommonPrefix(new String[] {"abc", "a"}) = "a"
 StringUtils.getCommonPrefix(new String[] {"ab", "abxyz"}) = "ab"
{code}

Where the same method would yield:
{code}
StringUtils.same("abc", "a") = null
StringUtils.same("ab", "abxyz") = null
StringUtils.same("123", "1234") = null
{code}

Also I was thinking there could also be an overloaded method with a default if 
the result is empty:
same(String str1, String str2)
same(String str1, String str2, String defaultIfEmpty)

I agree the name isn't great, so if either of you can think of a better name I 
am all for it.

> StringUtils.same opposite method to StringUtils.differ
> ------------------------------------------------------
>
>                 Key: LANG-1030
>                 URL: https://issues.apache.org/jira/browse/LANG-1030
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 3.3.2
>            Reporter: Michael Bazos
>            Priority: Trivial
>              Labels: StringUtils
>             Fix For: Review Patch, Discussion
>
>
> This is pretty easy to do but I have seen this come up and was surprised to 
> find that StringUtils didn't have a utility method.
> The difference() method is described as doing the following:
> Compares two Strings, and returns the portion where they differ.
> What I am proposing is essentially the opposite of the difference method 
> called same().  This method would compare two String and return a new String 
> when they are the same.
> This is essentially the implementation:
> {code:java}
>     public static String same(String str1, String str2) {
>         if (str1 != null && StringUtils.equalsIgnoreCase(str1, str2)) {
>             return new String(str1);
>         }
>         return null;
>     }
> {code}
> {code:java}
> StringUtils.same(null, null) = null
> StringUtils.same("", "") = "";
> StringUtils.same("123", "") = null
> StringUtils.same("123", "123") = "123";
> {code}
> If there is already a way to do this using the apache lang library please 
> point me in the right direction.  Otherwise I would be more than happy to do 
> the testing, coding and documentation for this.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to