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

feature: Add a new standard join configuration for spaces #962

Merged
merged 2 commits into from
Aug 27, 2023
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
13 changes: 13 additions & 0 deletions api/src/main/java/net/kyori/adventure/text/JoinConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public interface JoinConfiguration extends Buildable<JoinConfiguration, JoinConf
return JoinConfigurationImpl.STANDARD_NEW_LINES;
}

/**
* Provides a join configuration with no prefix or suffix that simply joins the components together using the {@link Component#space()} component.
*
* <p>A purely text based example of this syntax, without introducing the concepts of components, would join the two strings 'hello' and 'there' together,
* creating the following output: 'hello there'.</p>
*
* @return the join configuration
* @since 4.14.0
RedDaedalus marked this conversation as resolved.
Show resolved Hide resolved
*/
static @NotNull JoinConfiguration spaces() {
return JoinConfigurationImpl.STANDARD_SPACES;
}

/**
* Provides a join configuration with no prefix or suffix that simply joins the components together using a single comma, matching a CSV like layout.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class JoinConfigurationImpl implements JoinConfiguration {
static final JoinConfigurationImpl NULL = new JoinConfigurationImpl();

static final JoinConfiguration STANDARD_NEW_LINES = JoinConfiguration.separator(Component.newline());
static final JoinConfiguration STANDARD_SPACES = JoinConfiguration.separator(Component.space());
static final JoinConfiguration STANDARD_COMMA_SEPARATED = JoinConfiguration.separator(Component.text(","));
static final JoinConfiguration STANDARD_COMMA_SPACE_SEPARATED = JoinConfiguration.separator(Component.text(", "));
static final JoinConfiguration STANDARD_ARRAY_LIKE = JoinConfiguration.builder()
Expand Down
15 changes: 15 additions & 0 deletions api/src/test/java/net/kyori/adventure/text/JoinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,21 @@ final void testStandardJoinConfigurationsNewLines() {
);
}

@Test
final void testStandardJoinConfigurationsSpaces() {
final Component result = Component.join(JoinConfiguration.spaces(), Component.text("line 1"), Component.text("line 2"), Component.text("line 3"));
assertEquals(
Component.text()
.append(Component.text("line 1"))
.append(Component.space())
.append(Component.text("line 2"))
.append(Component.space())
.append(Component.text("line 3"))
.build(),
result
);
}

@Test
final void testStandardJoinConfigurationsCommas() {
final Component result = Component.join(JoinConfiguration.commas(false), Component.text("line 1"), Component.text("line 2"), Component.text("line 3"));
Expand Down