Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ROMVoid95 committed Jan 17, 2023
1 parent 1e7351f commit d956a27
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static ContextMenuList from(Collection<ContextMenu> list)

private ContextMenuList(NoDuplicateList<ContextMenu> noDuplicateList)
{
super(noDuplicateList.collection());
super(noDuplicateList.distinctCollection());
this.commandNames = noDuplicateList.mapped(ContextMenu::getName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static SlashCommandList from(Collection<SlashCommand> list)

private SlashCommandList(NoDuplicateList<SlashCommand> noDuplicateList)
{
super(noDuplicateList.collection());
super(noDuplicateList.distinctCollection());
this.commandNames = noDuplicateList.mapped(SlashCommand::getName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public abstract class SlashCommand extends Command
@Getter
protected Map<DiscordLocale, String> descriptionLocalization = new HashMap<>();

@Setter
protected String guildId = null;

@Getter
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/com/readonlydev/common/utils/NoDuplicateList.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* This file is part of JDATools, licensed under the MIT License (MIT).
*
* Copyright (c) ROMVoid95
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.readonlydev.common.utils;

import java.util.Collection;
Expand All @@ -6,14 +30,13 @@

public record NoDuplicateList<T>(Collection<T> collection)
{
@Override
public Collection<T> collection()
public Collection<T> distinctCollection()
{
return collection.stream().distinct().toList();
return collection().stream().distinct().toList();
}

public <R> List<R> mapped(Function<T, R> function)
{
return collection().stream().map(function).toList();
return distinctCollection().stream().map(function).toList();
}
}

0 comments on commit d956a27

Please sign in to comment.