RockyMM commented on code in PR #375:
URL: https://github.com/apache/commons-text/pull/375#discussion_r1030707089
##########
src/main/java/org/apache/commons/text/AlphabetConverter.java:
##########
@@ -104,11 +104,7 @@ private static Integer[] convertCharsToIntegers(final
Character[] chars) {
if (ArrayUtils.isEmpty(chars)) {
return ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY;
}
- final Integer[] integers = new Integer[chars.length];
- for (int i = 0; i < chars.length; i++) {
- integers[i] = (int) chars[i];
- }
- return integers;
+ return Arrays.stream(chars).map(aChar -> (int)
aChar).toArray(Integer[]::new);
Review Comment:
If I may jump in, _personally_ and strictly _personally_ :), I find
stream-map-reduce flow to be somehow more readable. I immediately recognize
that we are converting one set of data to another set. It would help even more
with proper formatting where each stream operation is in a separate line. It
could be argued that using a functional paradigm for data manipulation as of
late is - idiomatic in Java.
With `setAll` approach I (personally) need to think for a moment about what
is actually happening.
After all, there is no right way -> both imperative and functional
approaches are correct, only matters of personal preference.
--
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]