Skip to content

Commit

Permalink
[SPARK-51107][CORE] Refactor CommandBuilderUtils#join to reuse the li…
Browse files Browse the repository at this point in the history
…nes about strings join and reduce the redundant lines

### What changes were proposed in this pull request?
- Refactor CommandBuilderUtils#join to reuse the lines about strings join and reduce the redundant lines.

### Why are the changes needed?

- Refactor CommandBuilderUtils#join to reuse the lines about strings join and reduce the redundant lines.

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?

No

Closes #49826 from RocMarshal/SPARK-51107.

Authored-by: Roc Marshal <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
  • Loading branch information
RocMarshal authored and LuciferYang committed Feb 7, 2025
1 parent 8d18df3 commit f4b729d
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -46,24 +47,15 @@ static boolean isEmpty(String s) {

/** Joins a list of strings using the given separator. */
static String join(String sep, String... elements) {
StringBuilder sb = new StringBuilder();
for (String e : elements) {
if (e != null) {
if (sb.length() > 0) {
sb.append(sep);
}
sb.append(e);
}
}
return sb.toString();
return join(sep, Arrays.asList(elements));
}

/** Joins a list of strings using the given separator. */
static String join(String sep, Iterable<String> elements) {
StringBuilder sb = new StringBuilder();
for (String e : elements) {
if (e != null) {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append(sep);
}
sb.append(e);
Expand Down

0 comments on commit f4b729d

Please sign in to comment.