refactor(core): remove redundant distinct method and its uses
This commit is contained in:
parent
d4a91f3251
commit
e7c35d9308
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user