Skip to content

Commit

Permalink
Use instead of
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed May 14, 2022
1 parent 66d2ac3 commit 5a5e515
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions api/src/main/java/net/kyori/adventure/text/ComponentCompaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ static Component compact(final @NotNull Component self, final @Nullable Style pa

if (childrenSize == 0) {
// no children, style can be further simplified if self is blank
if (isBlank(self)) {
optimized = optimized.style(simplifyStyleForBlank(self.style()));
if (isBlank(optimized)) {
optimized = optimized.style(simplifyStyleForBlank(optimized.style()));
}

// leaf nodes do not need to be further optimized - there is no point
return optimized;
}

// if there is only one child, check if self a useless empty component
if (childrenSize == 1 && self instanceof TextComponent) {
final TextComponent textComponent = (TextComponent) self;
if (childrenSize == 1 && optimized instanceof TextComponent) {
final TextComponent textComponent = (TextComponent) optimized;

if (textComponent.content().isEmpty()) {
final Component child = children.get(0);
Expand Down Expand Up @@ -140,8 +140,8 @@ static Component compact(final @NotNull Component self, final @Nullable Style pa
}

// no children, style can be further simplified if self is blank
if (childrenToAppend.isEmpty() && isBlank(self)) {
optimized = optimized.style(simplifyStyleForBlank(self.style()));
if (childrenToAppend.isEmpty() && isBlank(optimized)) {
optimized = optimized.style(simplifyStyleForBlank(optimized.style()));
}

return optimized.children(childrenToAppend);
Expand Down Expand Up @@ -191,18 +191,19 @@ static Component compact(final @NotNull Component self, final @Nullable Style pa
}

/**
* Checks whether the Component is blank (a TextComponent containing only space characters)
* Checks whether the Component is blank (a TextComponent containing only space characters).
*
* @param component the component to check
* @return true if the provided component is blank, false otherwise
*/
private static boolean isBlank(Component component) {
private static boolean isBlank(final Component component) {
if (component instanceof TextComponent) {
final TextComponent textComponent = (TextComponent) component;

String content = textComponent.content();
final String content = textComponent.content();

for (int i = 0; i < content.length(); i++) {
char c = content.charAt(i);
final char c = content.charAt(i);
if (c != ' ') return false;
}

Expand All @@ -213,7 +214,7 @@ private static boolean isBlank(Component component) {

/**
* Simplify the provided style to remove any information that is redundant,
* given that the content is blank
* given that the content is blank.
*
* @param style style to simplify
* @return a new, simplified style
Expand Down

0 comments on commit 5a5e515

Please sign in to comment.