Skip to content

Commit f9fa20d

Browse files
committed
use delegate in adapter
1 parent e531f96 commit f9fa20d

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/BotCommandAdapter.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
import net.dv8tion.jda.api.interactions.commands.Command;
77
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
88
import org.jetbrains.annotations.Contract;
9-
import org.togetherjava.tjbot.commands.componentids.ComponentId;
109
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
10+
import org.togetherjava.tjbot.commands.componentids.ComponentIdInteractor;
1111
import org.togetherjava.tjbot.commands.componentids.Lifespan;
1212

13-
import java.util.Arrays;
1413
import java.util.List;
1514
import java.util.Objects;
1615

@@ -38,11 +37,10 @@
3837
* Registration of commands can be done in {@link Features}.
3938
*/
4039
public abstract class BotCommandAdapter implements BotCommand {
41-
private final String name;
4240
private final Command.Type type;
4341
private final CommandVisibility visibility;
4442
private final CommandData data;
45-
private ComponentIdGenerator componentIdGenerator;
43+
private final ComponentIdInteractor componentIdInteractor;
4644

4745
/**
4846
* Creates a new adapter with the given data.
@@ -54,17 +52,17 @@ protected BotCommandAdapter(CommandData data, CommandVisibility visibility) {
5452
this.data = Objects.requireNonNull(data, "The data shouldn't be null");
5553
this.visibility = Objects.requireNonNull(visibility, "The visibility shouldn't be null");
5654

57-
this.name = data.getName();
58-
this.type = data.getType();
55+
type = data.getType();
56+
componentIdInteractor = new ComponentIdInteractor(data.getName());
5957
}
6058

6159
@Override
6260
public final String getName() {
63-
return name;
61+
return componentIdInteractor.getName();
6462
}
6563

6664
@Override
67-
public Command.Type getType() {
65+
public final Command.Type getType() {
6866
return type;
6967
}
7068

@@ -81,8 +79,7 @@ public CommandData getData() {
8179
@Override
8280
@Contract(mutates = "this")
8381
public final void acceptComponentIdGenerator(ComponentIdGenerator generator) {
84-
componentIdGenerator =
85-
Objects.requireNonNull(generator, "The given generator cannot be null");
82+
componentIdInteractor.acceptComponentIdGenerator(generator);
8683
}
8784

8885
@SuppressWarnings("NoopMethodInAbstractClass")
@@ -113,7 +110,7 @@ public void onSelectionMenu(SelectMenuInteractionEvent event, List<String> args)
113110
*/
114111
@SuppressWarnings("OverloadedVarargsMethod")
115112
protected final String generateComponentId(String... args) {
116-
return generateComponentId(Lifespan.REGULAR, args);
113+
return componentIdInteractor.generateComponentId(args);
117114
}
118115

119116
/**
@@ -130,7 +127,6 @@ protected final String generateComponentId(String... args) {
130127
*/
131128
@SuppressWarnings({"OverloadedVarargsMethod", "WeakerAccess"})
132129
protected final String generateComponentId(Lifespan lifespan, String... args) {
133-
return componentIdGenerator.generate(new ComponentId(getName(), Arrays.asList(args)),
134-
lifespan);
130+
return componentIdInteractor.generateComponentId(lifespan, args);
135131
}
136132
}

0 commit comments

Comments
 (0)