ppkarwasz commented on code in PR #1327:
URL: https://github.com/apache/commons-lang/pull/1327#discussion_r1873789039
##########
src/main/java/org/apache/commons/lang3/StringUtils.java:
##########
@@ -2888,17 +2876,20 @@ public static int indexOfAnyBut(final CharSequence seq,
final CharSequence searc
if (isEmpty(seq) || isEmpty(searchChars)) {
return INDEX_NOT_FOUND;
}
- final int strLen = seq.length();
- for (int i = 0; i < strLen; i++) {
- final char ch = seq.charAt(i);
- final boolean chFound = CharSequenceUtils.indexOf(searchChars, ch,
0) >= 0;
- if (i + 1 < strLen && Character.isHighSurrogate(ch)) {
- final char ch2 = seq.charAt(i + 1);
- if (chFound && CharSequenceUtils.indexOf(searchChars, ch2, 0)
< 0) {
- return i;
- }
- } else if (!chFound) {
- return i;
+ final Set<Integer> seqSetCodePoints =
seq.codePoints().boxed().collect(Collectors.toSet()); // JDK >=10:
Collectors::toUnmodifiableSet
+ final Set<Integer> searchSetCodePoints =
searchChars.codePoints().boxed()
+ .collect(Collectors.toSet()); // JDK >=10:
Collectors::toUnmodifiableSet
+ final Set<Integer> complSetCodePoints =
seqSetCodePoints.stream().filter(((Predicate<Integer>)
searchSetCodePoints::contains).negate()) // JDK >=11:
Predicate.not(searchSetCodePoints::contains)
+ .collect(Collectors.toSet()); // JDK >=10:
Collectors::toUnmodifiableSet
Review Comment:
We don't need to use Java 9. The above stream expression is almost identical
to the [loop I posted
below](https://github.com/apache/commons-lang/pull/1327#discussion_r1873091371).
In this case the use of a `Stream` seems pretty much syntactic sugar.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]