Package org.javacord.core.util.cache
Class ChannelCache
- java.lang.Object
-
- org.javacord.core.util.cache.ChannelCache
-
public class ChannelCache extends java.lang.Object
An immutable cache for all channel entities.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ChannelCache
addChannel(Channel channel)
Adds a channel to the cache.static ChannelCache
empty()
Gets an empty channel cache.java.util.Optional<Channel>
getChannelById(long id)
Gets a channel by its id.java.util.Set<Channel>
getChannels()
Gets all channels in the cache.java.util.Set<ServerChannel>
getChannelsOfServer(long serverId)
Gets all channels of the server with the given id.<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.<T extends Channel>
java.util.Set<T>getChannelsWithTypes(ChannelType... types)
Gets all channels that have one of the given types.java.util.Optional<PrivateChannel>
getPrivateChannelByUserId(long userId)
Gets a private channel by the user's id.ChannelCache
removeChannel(Channel channel)
Removes a channel from the cache.
-
-
-
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.
-
getChannelsWithTypes
public <T extends Channel> java.util.Set<T> getChannelsWithTypes(ChannelType... types)
Gets all channels that have one of the given types.- Type Parameters:
T
- A type that at least all channels of the given types share. E.g., if the providedtypes
parameter isChannelType.SERVER_TEXT_CHANNEL
andChannelType.SERVER_VOICE_CHANNEL
,T
can beServerChannel
but must not beTextChannel
.- Parameters:
types
- The types of the channels to get.- Returns:
- All channels that are of one of the given types.
-
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 providedtype
parameter isChannelType.SERVER_TEXT_CHANNEL
T
can beServerTextChannel
orServerChannel
but must not beServerVoiceChannel
orVoiceChannel
.- 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.
-
-