Class ChannelCacheViewImpl<T extends Channel>

java.lang.Object
net.dv8tion.jda.internal.utils.cache.ReadWriteLockCache<T>
net.dv8tion.jda.internal.utils.cache.ChannelCacheViewImpl<T>
All Implemented Interfaces:
Iterable<T>, CacheView<T>, ChannelCacheView<T>, SnowflakeCacheView<T>
Direct Known Subclasses:
SortedChannelCacheViewImpl

public class ChannelCacheViewImpl<T extends Channel> extends ReadWriteLockCache<T> implements ChannelCacheView<T>
  • Constructor Details

    • ChannelCacheViewImpl

      public ChannelCacheViewImpl(Class<T> type)
  • Method Details

    • put

      @Nullable public <C extends T> C put(C element)
    • remove

      @Nullable public <C extends T> C remove(ChannelType type, long id)
    • remove

      public <C extends T> C remove(C channel)
    • removeIf

      public <C extends T> void removeIf(Class<C> typeFilter, Predicate<? super C> predicate)
    • clear

      public void clear()
    • ofType

      @Nonnull public <C extends T> ChannelCacheViewImpl<T>.FilteredCacheView<C> ofType(@Nonnull Class<C> type)
      Description copied from interface: ChannelCacheView
      Creates a decorator around this cache, filtered to only provide access to the given type.
      Specified by:
      ofType in interface ChannelCacheView<T extends Channel>
      Type Parameters:
      C - The type parameter
      Parameters:
      type - The type class (Like TextChannel.class)
      Returns:
      The filtered cache view
    • forEach

      public void forEach(Consumer<? super T> action)
      Specified by:
      forEach in interface Iterable<T extends Channel>
    • asList

      @Nonnull public List<T> asList()
      Description copied from interface: CacheView
      Creates an immutable snapshot of the current cache state.
      This will copy all elements contained in this cache into a list.
      This will be sorted for a SortedSnowflakeCacheView.
      Specified by:
      asList in interface CacheView<T extends Channel>
      Returns:
      Immutable list of cached elements
    • asSet

      @Nonnull public Set<T> asSet()
      Description copied from interface: CacheView
      Creates an immutable snapshot of the current cache state.
      This will copy all elements contained in this cache into a set.
      Specified by:
      asSet in interface CacheView<T extends Channel>
      Returns:
      Immutable set of cached elements
    • lockedIterator

      @Nonnull public ClosableIterator<T> lockedIterator()
      Description copied from interface: CacheView
      Returns an iterator with direct access to the underlying data store. This iterator does not support removing elements.
      After usage this iterator should be closed to allow modifications by the library internals.

      Note: Order is not preserved in this iterator to be more efficient, if order is desired use Iterable.iterator() instead!

      Specified by:
      lockedIterator in interface CacheView<T extends Channel>
      Returns:
      ClosableIterator holding a read-lock on the data structure.
    • size

      public long size()
      Description copied from interface: CacheView
      The current size of this cache
      This is a long as it may be a projected view of multiple caches (See CacheView.all(java.util.function.Supplier))

      This is more efficient than creating a list or set snapshot first as it checks the size of the internal cache directly.

      Specified by:
      size in interface CacheView<T extends Channel>
      Returns:
      The current size of this cache
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: CacheView
      Whether the cache is empty

      This is more efficient than creating a list or set snapshot first as it checks the size of the internal cache directly.
      On a projected cache view this will simply look through all projected views and return false the moment it finds one that is not empty.

      Specified by:
      isEmpty in interface CacheView<T extends Channel>
      Returns:
      True, if this cache is currently empty
    • getElementsByName

      @Nonnull public List<T> getElementsByName(@Nonnull String name, boolean ignoreCase)
      Description copied from interface: CacheView
      Creates an immutable list of all elements matching the given name.
      For a MemberCacheView this will check the Effective Name of the cached members.
      Specified by:
      getElementsByName in interface CacheView<T extends Channel>
      Parameters:
      name - The name to check
      ignoreCase - Whether to ignore case when comparing names
      Returns:
      Immutable list of elements with the given name
    • stream

      @Nonnull public Stream<T> stream()
      Description copied from interface: CacheView
      Creates a Stream of all cached elements.
      This will be sorted for a SortedSnowflakeCacheView.
      Specified by:
      stream in interface CacheView<T extends Channel>
      Returns:
      Stream of elements
    • parallelStream

      @Nonnull public Stream<T> parallelStream()
      Description copied from interface: CacheView
      Creates a parallel Stream of all cached elements.
      This will be sorted for a SortedSnowflakeCacheView.
      Specified by:
      parallelStream in interface CacheView<T extends Channel>
      Returns:
      Parallel Stream of elements
    • getElementById

      @Nullable public T getElementById(long id)
      Description copied from interface: SnowflakeCacheView
      Retrieves the entity represented by the provided ID.
      Specified by:
      getElementById in interface SnowflakeCacheView<T extends Channel>
      Parameters:
      id - The ID of the entity
      Returns:
      Possibly-null entity for the specified ID
    • getElementById

      public T getElementById(@Nonnull ChannelType type, long id)
      Description copied from interface: ChannelCacheView
      Retrieves the entity represented by the provided ID.
      Specified by:
      getElementById in interface ChannelCacheView<T extends Channel>
      Parameters:
      type - The expected ChannelType
      id - The ID of the entity
      Returns:
      Possibly-null entity for the specified ID, null if the expected type is different from the actual type
    • iterator

      @Nonnull public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T extends Channel>