Class ShardCacheViewImpl

java.lang.Object
net.dv8tion.jda.internal.utils.cache.ReadWriteLockCache<JDA>
net.dv8tion.jda.internal.utils.cache.ShardCacheViewImpl
All Implemented Interfaces:
Iterable<JDA>, CacheView<JDA>, ShardCacheView

public class ShardCacheViewImpl extends ReadWriteLockCache<JDA> implements ShardCacheView
  • Constructor Details

    • ShardCacheViewImpl

      public ShardCacheViewImpl()
    • ShardCacheViewImpl

      public ShardCacheViewImpl(int initialCapacity)
  • Method Details

    • clear

      public void clear()
    • remove

      public JDA remove(int shardId)
    • getMap

      public gnu.trove.map.TIntObjectMap<JDA> getMap()
    • keySet

      public gnu.trove.set.TIntSet keySet()
    • forEach

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

      @Nonnull public List<JDA> 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<JDA>
      Returns:
      Immutable list of cached elements
    • asSet

      @Nonnull public Set<JDA> 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<JDA>
      Returns:
      Immutable set of cached elements
    • lockedIterator

      @Nonnull public LockIterator<JDA> 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<JDA>
      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<JDA>
      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<JDA>
      Returns:
      True, if this cache is currently empty
    • getElementsByName

      @Nonnull public List<JDA> 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<JDA>
      Parameters:
      name - The name to check
      ignoreCase - Whether to ignore case when comparing names
      Returns:
      Immutable list of elements with the given name
    • spliterator

      public Spliterator<JDA> spliterator()
      Specified by:
      spliterator in interface Iterable<JDA>
    • stream

      @Nonnull public Stream<JDA> 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<JDA>
      Returns:
      Stream of elements
    • parallelStream

      @Nonnull public Stream<JDA> 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<JDA>
      Returns:
      Parallel Stream of elements
    • iterator

      @Nonnull public Iterator<JDA> iterator()
      Specified by:
      iterator in interface Iterable<JDA>
    • getElementById

      public JDA getElementById(int id)
      Description copied from interface: ShardCacheView
      Retrieves the JDA instance represented by the provided shard ID.
      Specified by:
      getElementById in interface ShardCacheView
      Parameters:
      id - The ID of the entity
      Returns:
      Possibly-null entity for the specified shard ID
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object