commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Dang (JIRA)" <>
Subject [jira] Commented: (LANG-269) Shouldn't Commons Lang's StringUtils have a "common" string method?
Date Sun, 09 Jul 2006 13:32:30 GMT
    [ ] 

Michael Dang commented on LANG-269:

Scott, I think this is a very elegant approach.  I like the method name getCommonPrefix and
the idea of adding the indexOfDifference(String[]) method.  However, I would like to add one
comment about the indexOfDifference(String[]) calling indexOfDifference(String, String). 
Looking from the performance angle, this may not be an efficient implementation.  

For example, if most of the strings are long and pretty much the same except the last string
is very short (or null), all the beginning comparisions are wasted.  Although it is very natural
to call indexOfDifference(String, String) from within indexOfDifference(String[]), I would
think that it would perform better if we just scan through strings vertically, char by char,
and short circuit out once the first difference char is found.

Feel free to disagree and I maybe worrying about performance too much.  :)


> Shouldn't Commons Lang's StringUtils have a "common" string method?
> -------------------------------------------------------------------
>          Key: LANG-269
>          URL:
>      Project: Commons Lang
>         Type: New Feature

>  Environment: generic
>     Reporter: Michael Dang
>      Fix For: 3.0
>  Attachments: StringUtils.patch
> A method which accepts a string array and returns a string which is the common portion
of all the strings starting from the left, or more general form of that.
> This is very common operation.  For example, one may want to find the common directory
of a set of path strings.
> passing in:
> "/foo/f1.txt"
> "/foo/moo/f2.txt"
> "/foo/moo/f3.txt"
> should returns "/foo/"
> It is tedious to implement this in every project.  And I think Commons Lang StringUtils
should have some methods to help in this.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message