Interface CacheView<T>

    • Method Detail

      • asList

        java.util.List<T> asList()
        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.
        Returns:
        Immutable list of cached elements
      • asSet

        java.util.Set<T> asSet()
        Creates an immutable snapshot of the current cache state.
        This will copy all elements contained in this cache into a set.
        Returns:
        Immutable set of cached elements
      • size

        long size()
        The current size of this cache
        This is a long as it may be a projected view of multiple caches (See 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.

        Returns:
        The current size of this cache
      • isEmpty

        boolean isEmpty()
        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.

        Returns:
        True, if this cache is currently empty
      • getElementsByName

        java.util.List<T> getElementsByName​(java.lang.String name,
                                            boolean ignoreCase)
        Creates an immutable list of all elements matching the given name.
        For a MemberCacheView this will check the Effective Name of the cached members.
        Parameters:
        name - The name to check
        ignoreCase - Whether to ignore case when comparing names
        Returns:
        Immutable list of elements with the given name
        Throws:
        java.lang.IllegalArgumentException - If the provided name is null
      • getElementsByName

        default java.util.List<T> getElementsByName​(java.lang.String name)
        Creates an immutable list of all elements matching the given name.
        For a MemberCacheView this will check the Effective Name of the cached members.
        Parameters:
        name - The name to check
        Returns:
        Immutable list of elements with the given name
        Throws:
        java.lang.IllegalArgumentException - If the provided name is null
      • stream

        java.util.stream.Stream<T> stream()
        Creates a Stream of all cached elements.
        This will be sorted for a SortedSnowflakeCacheView.
        Returns:
        Stream of elements
      • parallelStream

        java.util.stream.Stream<T> parallelStream()
        Creates a parallel Stream of all cached elements.
        This will be sorted for a SortedSnowflakeCacheView.
        Returns:
        Parallel Stream of elements
      • collect

        default <R,​A> R collect​(java.util.stream.Collector<? super T,​A,​R> collector)
        Collects all cached entities into a single Collection using the provided Collector. Shortcut for stream().collect(collector).
        Type Parameters:
        R - The output type
        A - The accumulator type
        Parameters:
        collector - The collector used to collect the elements
        Returns:
        Resulting collections
        Throws:
        java.lang.IllegalArgumentException - If the provided collector is null
      • all

        static <E> CacheView<E> all​(java.util.Collection<? extends CacheView<E>> cacheViews)
        Creates a combined CacheView for all provided CacheView implementations. This allows to combine cache of multiple JDA sessions or Guilds.
        Type Parameters:
        E - The target type of the projection
        Parameters:
        cacheViews - Collection of CacheView implementations
        Returns:
        Combined CacheView spanning over all provided implementation instances
      • all

        static <E> CacheView<E> all​(java.util.function.Supplier<java.util.stream.Stream<CacheView<E>>> generator)
        Creates a combined CacheView for all provided CacheView implementations. This allows to combine cache of multiple JDA sessions or Guilds.
        Type Parameters:
        E - The target type of the projection
        Parameters:
        generator - Stream generator of CacheView implementations
        Returns:
        Combined CacheView spanning over all provided implementation instances
      • allShards

        static ShardCacheView allShards​(java.util.Collection<ShardCacheView> cacheViews)
        Creates a combined ShardCacheView for all provided ShardCacheView implementations.
        Parameters:
        cacheViews - Collection of ShardCacheView implementations
        Returns:
        Combined ShardCacheView spanning over all provided implementation instances
      • allShards

        static ShardCacheView allShards​(java.util.function.Supplier<java.util.stream.Stream<ShardCacheView>> generator)
        Creates a combined ShardCacheView for all provided ShardCacheView implementations.
        Parameters:
        generator - Stream generator of ShardCacheView implementations
        Returns:
        Combined ShardCacheView spanning over all provided implementation instances
      • allSnowflakes

        static <E extends ISnowflakeSnowflakeCacheView<E> allSnowflakes​(java.util.Collection<SnowflakeCacheView<E>> cacheViews)
        Creates a combined SnowflakeCacheView for all provided SnowflakeCacheView implementations.
        This allows to combine cache of multiple JDA sessions or Guilds.
        Type Parameters:
        E - The target type of the chain
        Parameters:
        cacheViews - Collection of SnowflakeCacheView implementations
        Returns:
        Combined SnowflakeCacheView spanning over all provided implementation instances
      • allSnowflakes

        static <E extends ISnowflakeSnowflakeCacheView<E> allSnowflakes​(java.util.function.Supplier<java.util.stream.Stream<SnowflakeCacheView<E>>> generator)
        Creates a combined SnowflakeCacheView for all provided SnowflakeCacheView implementations.
        This allows to combine cache of multiple JDA sessions or Guilds.
        Type Parameters:
        E - The target type of the chain
        Parameters:
        generator - Stream generator of SnowflakeCacheView implementations
        Returns:
        Combined SnowflakeCacheView spanning over all provided implementation instances
      • allMembers

        static UnifiedMemberCacheView allMembers​(java.util.Collection<MemberCacheView> cacheViews)
        Creates a combined UnifiedMemberCacheView for all provided MemberCacheView implementations.
        This allows to combine cache of multiple JDA sessions or Guilds.
        Parameters:
        cacheViews - Collection of MemberCacheView instances
        Returns:
        Combined MemberCacheView spanning over all provided instances
      • allMembers

        static UnifiedMemberCacheView allMembers​(java.util.function.Supplier<java.util.stream.Stream<MemberCacheView>> generator)
        Creates a combined UnifiedMemberCacheView for all provided MemberCacheView implementations.
        This allows to combine cache of multiple JDA sessions or Guilds.
        Parameters:
        generator - Stream generator of MemberCacheView instances
        Returns:
        Combined MemberCacheView spanning over all provided instances