OAK-11774 : removed usage of guava splitter#2380
Conversation
Commit-Check ✔️ |
| protected static final List<String> NODE_LEVELS = Splitter.on(",").trimResults() | ||
| .omitEmptyStrings().splitToList(System.getProperty("nodeLevels", "10,5,2")); | ||
| protected static final List<String> NODE_LEVELS = Arrays.stream(System.getProperty("nodeLevels", "10,5,2").split(",")) | ||
| .map(String::trim) |
There was a problem hiding this comment.
Of course the above should be refactored to be there just once, and to use the SystemPropertySupplies, but that would be a different ticket.
| Splitter.on(DELIM).limit(2).splitToList(name).get(1)).get(0); | ||
| return Arrays.stream(name.split(DELIM, 2)) | ||
| .skip(1) | ||
| .findFirst() |
There was a problem hiding this comment.
is this right as compared to "limit(2)?
There was a problem hiding this comment.
name.split(DELIM, 2) would only get 2 elements.
| .map(String::trim) | ||
| .filter(s -> !s.isEmpty()) | ||
| .findFirst() | ||
| .orElse(null); |
There was a problem hiding this comment.
What's this? I assume it's ok but I do not understand :-)
There was a problem hiding this comment.
I have asked the co-pilot to optimize this code, and it created this one.
oak-run/src/main/java/org/apache/jackrabbit/oak/run/DataStoreCommand.java
Show resolved
Hide resolved
| temporaryFolder.newFolder().getAbsolutePath())); | ||
| if (!StringUtils.isEmpty(additionalParams)) { | ||
| argsList.addAll(Splitter.on(" ").splitToList(additionalParams)); | ||
| argsList.addAll(Arrays.stream(additionalParams.split(" ")).collect(Collectors.toList())); |
...ent/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
Show resolved
Hide resolved
oak-run/src/main/java/org/apache/jackrabbit/oak/run/MetricsExporterFixtureProvider.java
Show resolved
Hide resolved
| splits = Arrays.stream(line.split("")).map(String::trim).collect(Collectors.toList()); | ||
| } else { | ||
| splits = Arrays.stream(line.split(" ")).collect(Collectors.toList()); | ||
| } |
There was a problem hiding this comment.
I do not think that the code does still the same in case the trimmed line is empty.
There was a problem hiding this comment.
I quickly tried it in a Java console and the resulting arrays are of different length.
There was a problem hiding this comment.
thanks for @mbaedke, could you please the test cases that you tried.
Also, this class has extensive test coverage and they all passed after these changes, but still we might have missed few cases, would be more than happy to add them.
There was a problem hiding this comment.
This class must parse a file that contains either three empty spaces on a line or a line with three entries separated by a space. Moreover, the unit cases provide extensive coverage for that.
There was a problem hiding this comment.
Well, I tried the following in a JShell console in Idea;
import org.apache.jackrabbit.guava.common.base.Splitter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
String separator = " ";
String input = " ";
List<String> guavaList = Splitter.on(separator).splitToList(input);
System.out.println("Guava: " + guavaList.size());
List<String> jseList = Arrays.stream(" ".split("")).map(String::trim).collect(Collectors.toList());
System.out.println("Stream API: " + jseList.size());
There was a problem hiding this comment.
The output was:
import org.apache.jackrabbit.guava.common.base.Splitter
import java.util.Arrays
import java.util.List
import java.util.stream.Collectors
field String separator = " "
Defined field String input = " "
Defined field List<String> guavaList = [, , , ]
System.out.println("Guava: " + guavaList.size());
Guava: 4
Defined field List<String> jseList = [, , ]
System.out.println("Stream API: " + jseList.size());
Stream API: 3
There was a problem hiding this comment.
Since the lists are of different length, I didn't look further.
There was a problem hiding this comment.
I don't understand. Wrong PR?
There was a problem hiding this comment.
they are added to improve the test coverage.
There was a problem hiding this comment.
Yes, so something completely different :)
…de using -1 limit in split method
|


No description provided.