refactor(core): remove redundant distinct method and its uses
All checks were successful
github-mirror / push-github (push) Successful in 4s
Build / Gradle-Build (push) Successful in 32s
Test / Gradle-Test (push) Successful in 46s

This commit is contained in:
Tueem 2025-03-17 00:16:26 +01:00
parent d4a91f3251
commit e7c35d9308
Signed by: tueem
GPG Key ID: F2CE0513D231AD7A
2 changed files with 3 additions and 20 deletions

View File

@ -66,13 +66,13 @@ public class SlashCommandDefinition {
.map(x -> x.parent())
.toList();
return InteractionIdentifier.distinct(subCommandGroups).toArray(SlashCommandIdentifier[]::new);
return subCommandGroups.toArray(SlashCommandIdentifier[]::new);
}
public SlashCommandIdentifier[] getSubCommands() {
if (isRootCommand)
return null;
return InteractionIdentifier.distinct(entries.stream().filter(x -> x.parent() instanceof RootCommandIdentifier).toList()).toArray(SlashCommandIdentifier[]::new);
return entries.stream().filter(x -> x.parent() instanceof RootCommandIdentifier).toArray(SlashCommandIdentifier[]::new);
}
public SlashCommandIdentifier[] getSubCommands(String groupName) {
@ -84,7 +84,7 @@ public class SlashCommandDefinition {
.map(x -> x.parent().parent())
.toList();
return InteractionIdentifier.distinct(subCommands).toArray(SlashCommandIdentifier[]::new);
return subCommands.toArray(SlashCommandIdentifier[]::new);
}
@Override

View File

@ -1,8 +1,5 @@
package net.tomatentum.marinara.interaction.ident;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import net.tomatentum.marinara.interaction.InteractionType;
@ -37,20 +34,6 @@ public class InteractionIdentifier {
receiver.description = provider.description();
tryAddDescriptions(receiver.parent(), provider.parent());
}
/*
* TODO: Might not be the best solution. Propagating to future
* returns only one Identifier per name and takes the first present description
*/
public static Collection<InteractionIdentifier> distinct(List<InteractionIdentifier> identifiers) {
HashMap<String, InteractionIdentifier> distinctIdentifiers = new HashMap<>();
identifiers.forEach((x) -> {
InteractionIdentifier current = distinctIdentifiers.get(x.name());
if (current == null || (current.description().isBlank() && !x.description().isBlank()))
distinctIdentifiers.put(x.name(), x);
});
return distinctIdentifiers.values();
}
private InteractionIdentifier parent;
private String name;