Skip to content

Commit e86dc5e

Browse files
committed
Merge branch 'dev'
2 parents 6e3b3d9 + 97a3f31 commit e86dc5e

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ plugins {
44
}
55

66
group = "com.darvil"
7-
version = "2.1.0"
7+
version = "2.2.0"
88
description = "Text formatting utilities to easily format text on the terminal for Java."
99

1010
dependencies {
11-
implementation("com.darvil:utils:+")
11+
implementation("com.darvil:utils:0.6.1")
1212

1313
implementation("org.jetbrains:annotations:24.0.0")
1414
testImplementation(platform("org.junit:junit-bom:5.9.1"))

src/main/java/textFormatter/TextFormatter.java

+21-18
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class TextFormatter {
4747
/** A list of all the formatting options that should be applied to the text. */
4848
private final @NotNull ArrayList<FormatOption> formatOptions = new ArrayList<>(5);
4949

50-
/** A list of all the formatters that should be concatenated to this formatter. */
51-
private final @NotNull List<TextFormatter> concatList = new ArrayList<>(0);
50+
/** A list of all the values that should be concatenated to this formatter. */
51+
private final @NotNull List<Object> concatList = new ArrayList<>(0);
5252

5353
/** The parent formatter. Used when being concatenated to another formatter. */
5454
private @Nullable TextFormatter parent;
@@ -179,30 +179,33 @@ public TextFormatter withConcatGap(@Nullable String gap) {
179179
}
180180

181181
/**
182-
* Concatenates the specified formatters to this formatter.
183-
* @param formatters The formatters to concatenate.
182+
* Concatenates the specified values to the formatter. Another {@link TextFormatter} may also be concatenated.
183+
* @param objects The values to concatenate.
184184
*/
185-
public TextFormatter concat(@NotNull TextFormatter... formatters) {
186-
for (TextFormatter formatter : formatters) {
187-
// if it was already added to another formatter, throw an exception
188-
if (formatter.parent != null) {
189-
throw new IllegalArgumentException("Cannot concatenate a formatter that is already concatenated to another formatter.");
185+
public TextFormatter concat(@NotNull Object... objects) {
186+
for (var object : objects) {
187+
if (object instanceof TextFormatter tf) {
188+
this.concatFormatter(tf);
189+
continue;
190190
}
191-
formatter.parent = this;
192-
this.concatList.add(formatter);
191+
192+
this.concatList.add(object);
193193
}
194+
194195
return this;
195196
}
196197

197198
/**
198-
* Concatenates the specified strings to this formatter.
199-
* @param strings The strings to concatenate.
199+
* Properly concatenates the specified formatter to this formatter by also linking both formatters together.
200+
* @param formatter The formatter to concatenate.
200201
*/
201-
public TextFormatter concat(@NotNull String... strings) {
202-
for (var str : strings) {
203-
this.concatList.add(TextFormatter.of(str));
204-
}
205-
return this;
202+
private void concatFormatter(@NotNull TextFormatter formatter) {
203+
// if it was already added to another formatter, throw an exception
204+
if (formatter.parent != null)
205+
throw new IllegalArgumentException("Cannot concatenate a formatter that is already concatenated to another formatter.");
206+
207+
formatter.parent = this;
208+
this.concatList.add(formatter);
206209
}
207210

208211
/**

0 commit comments

Comments
 (0)