Skip to content

OAK-11774 : removed usage of guava splitter#2380

Merged
rishabhdaim merged 3 commits intotrunkfrom
OAK-11774
Jul 17, 2025
Merged

OAK-11774 : removed usage of guava splitter#2380
rishabhdaim merged 3 commits intotrunkfrom
OAK-11774

Conversation

@rishabhdaim
Copy link
Contributor

No description provided.

@github-actions
Copy link

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Contributor

@reschke reschke Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this right as compared to "limit(2)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name.split(DELIM, 2) would only get 2 elements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

.map(String::trim)
.filter(s -> !s.isEmpty())
.findFirst()
.orElse(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this? I assume it's ok but I do not understand :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have asked the co-pilot to optimize this code, and it created this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

temporaryFolder.newFolder().getAbsolutePath()));
if (!StringUtils.isEmpty(additionalParams)) {
argsList.addAll(Splitter.on(" ").splitToList(additionalParams));
argsList.addAll(Arrays.stream(additionalParams.split(" ")).collect(Collectors.toList()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a SP, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SP ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space character.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@rishabhdaim rishabhdaim requested a review from reschke July 10, 2025 15:05
Copy link
Contributor

@reschke reschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see comments)

@rishabhdaim rishabhdaim requested a review from reschke July 11, 2025 12:26
splits = Arrays.stream(line.split("")).map(String::trim).collect(Collectors.toList());
} else {
splits = Arrays.stream(line.split(" ")).collect(Collectors.toList());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that the code does still the same in case the trimmed line is empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quickly tried it in a Java console and the resulting arrays are of different length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the lists are of different length, I didn't look further.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank @mbaedke for the review, the issue has been fixed in d7580c7

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. Wrong PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are added to improve the test coverage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so something completely different :)

Copy link
Contributor

@mbaedke mbaedke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments.

@rishabhdaim rishabhdaim requested a review from mbaedke July 16, 2025 05:27
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
77.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@rishabhdaim rishabhdaim merged commit 06b7ff2 into trunk Jul 17, 2025
4 of 5 checks passed
@rishabhdaim rishabhdaim deleted the OAK-11774 branch July 17, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants