Class OrderUtil

    • Field Detail

      • ROLE_ORDER

        public static final Comparator<Role> ROLE_ORDER
        The ordering of Discord roles.

        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.

      • CHANNEL_ORDER

        public static final Comparator<GuildChannel> CHANNEL_ORDER
        The base ordering of Discord guild 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 of guild 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.

    • Constructor Detail

      • OrderUtil

        public OrderUtil()
    • Method Detail

      • orderGuildChannels

        public static Flux<GuildChannel> orderGuildChannels​(Flux<GuildChannel> channels)
        Sorts guild channels according to visual ordering in Discord. Channels at the top of the list are first. This sorts channels within the same category according to BUCKETED_CHANNEL_ORDER and then sorts those categories according to CHANNEL_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)
        Sorts roles according to visual ordering in Discord. Roles at the bottom of the list are first. This sorts roles according to ROLE_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.