Class OrderUtil
- java.lang.Object
-
- discord4j.core.util.OrderUtil
-
public final class OrderUtil extends Object
A utility class for the sorting ofroles
andguild channels
.
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<CategorizableChannel>
BUCKETED_CHANNEL_ORDER
The ordering ofguild channels
which considers channel type.static Comparator<GuildChannel>
CHANNEL_ORDER
The base ordering of Discordguild channels
.static Comparator<Role>
ROLE_ORDER
The ordering of Discordroles
.
-
Constructor Summary
Constructors Constructor Description OrderUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Flux<GuildChannel>
orderGuildChannels(Flux<GuildChannel> channels)
Sortsguild channels
according to visual ordering in Discord.static Flux<Role>
orderRoles(Flux<Role> roles)
Sortsroles
according to visual ordering in Discord.
-
-
-
Field Detail
-
ROLE_ORDER
public static final Comparator<Role> ROLE_ORDER
-
CHANNEL_ORDER
public static final Comparator<GuildChannel> CHANNEL_ORDER
The base ordering of Discordguild channels
.In Discord, two orderable entities may have the same "raw position," the position as reported by the "position" field. This conflict is resolved by comparing the creation time of the entities, reflected in their
IDs
.Note that this order is only applicable to channels if they are of the same type and in the same category. See
BUCKETED_CHANNEL_ORDER
for ordering between different channel types.
-
BUCKETED_CHANNEL_ORDER
public static final Comparator<CategorizableChannel> BUCKETED_CHANNEL_ORDER
The ordering ofguild channels
which considers channel type.Guild channels are first ordered by "bucket" which is determined by the type of the channels. Then,
CHANNEL_ORDER
is used to determine order within a buvket. Effectively, this only means that voice channels always appear below other types of channels.Note that this order is only applicable to channels if they are in the same category.
-
-
Method Detail
-
orderGuildChannels
public static Flux<GuildChannel> orderGuildChannels(Flux<GuildChannel> channels)
Sortsguild channels
according to visual ordering in Discord. Channels at the top of the list are first. This sorts channels within the same category according toBUCKETED_CHANNEL_ORDER
and then sorts those categories according toCHANNEL_ORDER
.This function can be used with
Flux.transform(Function)
for better chaining:guild.getChannels() .transform(OrderUtil::orderGuildChannels)
- Parameters:
channels
- The guild channels to sort.- Returns:
- The sorted guild channels.
-
orderRoles
public static Flux<Role> orderRoles(Flux<Role> roles)
Sortsroles
according to visual ordering in Discord. Roles at the bottom of the list are first. This sorts roles according toROLE_ORDER
.This function can be used with
Flux.transform(Function)
for better chaining:guild.getRoles() .transform(OrderUtil::orderRoles)
- Parameters:
roles
- The roles to sort.- Returns:
- The sorted roles.
-
-