jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ham1 <...@git.apache.org>
Subject [GitHub] jmeter pull request #342: More edge cases for changeCase function and slight...
Date Sat, 25 Nov 2017 21:14:04 GMT
Github user ham1 commented on a diff in the pull request:

    https://github.com/apache/jmeter/pull/342#discussion_r153054513
  
    --- Diff: src/functions/org/apache/jmeter/functions/ChangeCase.java ---
    @@ -127,19 +129,14 @@ public String getReferenceKey() {
             return DESC;
         }
     
    -    private static String camel(String str, boolean isFirstCapitalized) {
    -        StringBuilder builder = new StringBuilder(str.length());
    -        String[] tokens = NOT_ALPHANUMERIC_REGEX.split(str);
    -        for (int i = 0; i < tokens.length; i++) {
    -            String lowerCased = StringUtils.lowerCase(tokens[i]);
    -            if(i == 0) {
    -                builder.append(isFirstCapitalized ? StringUtils.capitalize(lowerCased):
    -                    lowerCased);
    -            } else {
    -                builder.append(StringUtils.capitalize(lowerCased));
    -            }
    +    private static String camel(String input, boolean uncapitalizeFirst) {
    +        List<String> tokens = Arrays.asList(SPLIT_CHARS.split(input)).stream()
    +                .filter(s -> !s.isEmpty()).map(StringUtils::lowerCase).map(StringUtils::capitalize)
    --- End diff --
    
    I generally prefer each item on a new line - I had to read this line twice as I missed
the map in the middle on first pass, whereas I think:
    ```java
    .filter(StringUtils::isNotEmpty)
    .map(StringUtils::lowerCase)
    .map(StringUtils::capitalize)
    ```
    is just that bit easier to read and doesn't get in the way of comprehending the code.


---

Mime
View raw message