Skip to content

Commit

Permalink
chore: Removed Component#compress
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Nov 29, 2024
1 parent d9e4582 commit e744a30
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,4 @@ public interface Component {
* Returns the text textStyle of this component.
*/
TextStyle getTextStyle();

/**
* Compresses this component. Removing empty subcommands and/or merging subcomponents if necessary.
*
* @return the compressed component
*/
default Component compress() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

/**
* A component that contains a list of components.
Expand Down Expand Up @@ -106,34 +105,6 @@ static ListComponent components(final TextStyle textStyle, final Collection<Comp
*/
List<Component> getComponents();

@Override
default Component compress() {
final var components = this.getComponents().stream()
.map(Component::compress)
.flatMap(component -> component instanceof ListComponent list
&& list.getTextStyle().equals(TextStyle.of())
? list.getComponents().stream()
: Stream.of(component))
.filter(component -> !component.equals(TextComponent.empty()))
.toList();
if (components.isEmpty()) {
return TextComponent.empty();
} else if (components.size() == 1) {
final var component = components.get(0);
if (component instanceof BuildableComponent<?, ?> buildable) {
return buildable.toBuilder()
.setTextStyle(getTextStyle().merge(component.getTextStyle()))
.build();
} else if (this.getTextStyle().equals(TextStyle.of())) {
return component;
} else {
return this.toBuilder().setComponents(List.of(component)).build();
}
} else {
return this.toBuilder().setComponents(components).build();
}
}

/**
* A builder for list components.
*/
Expand Down

0 comments on commit e744a30

Please sign in to comment.