Class ChannelCache


  • public class ChannelCache
    extends java.lang.Object
    An immutable cache for all channel entities.
    • Method Detail

      • empty

        public static ChannelCache empty()
        Gets an empty channel cache.
        Returns:
        An empty channel cache.
      • addChannel

        public ChannelCache addChannel​(Channel channel)
        Adds a channel to the cache.
        Parameters:
        channel - The channel to add.
        Returns:
        The new channel cache.
      • removeChannel

        public ChannelCache removeChannel​(Channel channel)
        Removes a channel from the cache.
        Parameters:
        channel - The channel to remove.
        Returns:
        The new channel cache.
      • getChannels

        public java.util.Set<Channel> getChannels()
        Gets all channels in the cache.
        Returns:
        All channels.
      • getChannelsOfServer

        public java.util.Set<ServerChannel> getChannelsOfServer​(long serverId)
        Gets all channels of the server with the given id.
        Parameters:
        serverId - The id of the server.
        Returns:
        All channels in the server.
      • getChannelsOfServerAndType

        public <T extends Channel> java.util.Set<T> getChannelsOfServerAndType​(long serverId,
                                                                               ChannelType type)
        Gets all channels with the given type of the server with the given id.
        Type Parameters:
        T - A type that at least all channels of the given type share. E.g., if the provided type parameter is ChannelType.SERVER_TEXT_CHANNEL T can be ServerTextChannel or ServerChannel but must not be ServerVoiceChannel or VoiceChannel.
        Parameters:
        serverId - The id of the server.
        type - The type of the channels in the server.
        Returns:
        All channels with the given type of the server with the given id.
      • getChannelById

        public java.util.Optional<Channel> getChannelById​(long id)
        Gets a channel by its id.

        This method has a time-complexity of O(1).

        Parameters:
        id - The id of the channel.
        Returns:
        The channel with the given id.
      • getPrivateChannelByUserId

        public java.util.Optional<PrivateChannel> getPrivateChannelByUserId​(long userId)
        Gets a private channel by the user's id.
        Parameters:
        userId - The id of the user.
        Returns:
        The private channel.