Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uses of StringUtil.joining() #2119

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Tweaked method name, code format
  • Loading branch information
jhy committed Jul 29, 2024
commit e6847486c51380f9cd961f205d8b4dbd29a7c786
19 changes: 7 additions & 12 deletions src/main/java/org/jsoup/nodes/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -1430,20 +1430,15 @@ public void tail(Node node, int depth) {
@see #wholeOwnText()
*/
public String wholeText() {
return getWholeText(nodeStream());
return wholeTextOf(nodeStream());
}

private static String getWholeText(Stream<Node> stream) {
private static String wholeTextOf(Stream<Node> stream) {
return stream.map(node -> {
if (node instanceof TextNode) {
return ((TextNode) node).getWholeText();
} else if (node.nameIs("br")) {
return "\n";
} else {
return "";
}
})
.collect(StringUtil.joining(""));
if (node instanceof TextNode) return ((TextNode) node).getWholeText();
if (node.nameIs("br")) return "\n";
return "";
}).collect(StringUtil.joining(""));
}

/**
Expand All @@ -1456,7 +1451,7 @@ private static String getWholeText(Stream<Node> stream) {
@since 1.15.1
*/
public String wholeOwnText() {
return getWholeText(childNodes.stream());
return wholeTextOf(childNodes.stream());
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/jsoup/select/Elements.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ public Elements val(String value) {
*/
public String text() {
return stream()
.map(Element::text)
.collect(StringUtil.joining(" "));
.map(Element::text)
.collect(StringUtil.joining(" "));
}

/**
Expand Down Expand Up @@ -257,8 +257,8 @@ public List<String> eachText() {
*/
public String html() {
return stream()
.map(Element::html)
.collect(StringUtil.joining("\n"));
.map(Element::html)
.collect(StringUtil.joining("\n"));
}

/**
Expand All @@ -269,8 +269,8 @@ public String html() {
*/
public String outerHtml() {
return stream()
.map(Element::outerHtml)
.collect(StringUtil.joining("\n"));
.map(Element::outerHtml)
.collect(StringUtil.joining("\n"));
}

/**
Expand Down
Loading