Skip to content

replacing StringBuilder with StringJoiner in order to simplify logic#4628

Open
renatoh wants to merge 6 commits into
apache:mainfrom
renatoh:simplify-code-by-switchign-from-StringBuilder-to-StringJoiner
Open

replacing StringBuilder with StringJoiner in order to simplify logic#4628
renatoh wants to merge 6 commits into
apache:mainfrom
renatoh:simplify-code-by-switchign-from-StringBuilder-to-StringJoiner

Conversation

@renatoh

@renatoh renatoh commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@janhoy
Following up on the discussion on #4606, I simplified the creation of URLs by moving from StringBuilder to the more flexible StringJoiner.

I had to change the signature of the public method StrUtils.partialURLEncodeVal, since it was couple to a StringBuilder, now it returns the encodedUrl rather than adding it to the passed in StringBuilder, which is more flexible.
Not sure if I can just change the signature of such a method or if I need to keep old method.

Comment thread solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java Outdated
renatoh and others added 2 commits July 23, 2026 14:16
@epugh epugh self-assigned this Jul 23, 2026
final StringBuilder sb = new StringBuilder(128);
boolean first = true;

var output = new StringJoiner("&", "?", "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interesting pattern, I've never seen StringJoiner before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @epugh, it has been around for a while, since Java 8, but I have only discovered it recently and since then I have been using it quite frequently, it saves you exactly those isFirst checks.

@epugh

epugh commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

I marked it no-changelog as there is no user impact on this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants