Package net.dv8tion.jda.core.utils.cache
Interface CacheView<T>
-
- Type Parameters:
T
- The cache type
- All Superinterfaces:
java.lang.Iterable<T>
- All Known Subinterfaces:
MemberCacheView
,ShardCacheView
,SnowflakeCacheView<T>
,UnifiedMemberCacheView
- All Known Implementing Classes:
net.dv8tion.jda.core.utils.cache.impl.AbstractCacheView
,CacheView.SimpleCacheView
,ShardCacheViewImpl
,ShardCacheViewImpl.UnifiedShardCacheViewImpl
public interface CacheView<T> extends java.lang.Iterable<T>
Read-only view on internal JDA cache of items.
This can be useful to check information such as size without creating an immutable snapshot first.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
CacheView.SimpleCacheView<T>
Basic implementation ofCacheView
interface.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <E> CacheView<E>
all(java.util.Collection<? extends CacheView<E>> cacheViews)
Creates a combinedCacheView
for all provided CacheView implementations.static <E> CacheView<E>
all(java.util.function.Supplier<java.util.stream.Stream<CacheView<E>>> generator)
Creates a combinedCacheView
for all provided CacheView implementations.static UnifiedMemberCacheView
allMembers(java.util.Collection<MemberCacheView> cacheViews)
Creates a combinedUnifiedMemberCacheView
for all provided MemberCacheView implementations.static UnifiedMemberCacheView
allMembers(java.util.function.Supplier<java.util.stream.Stream<MemberCacheView>> generator)
Creates a combinedUnifiedMemberCacheView
for all provided MemberCacheView implementations.static ShardCacheView
allShards(java.util.Collection<ShardCacheView> cacheViews)
Creates a combinedShardCacheView
for all provided ShardCacheView implementations.static ShardCacheView
allShards(java.util.function.Supplier<java.util.stream.Stream<ShardCacheView>> generator)
Creates a combinedShardCacheView
for all provided ShardCacheView implementations.static <E extends ISnowflake>
SnowflakeCacheView<E>allSnowflakes(java.util.Collection<SnowflakeCacheView<E>> cacheViews)
Creates a combinedSnowflakeCacheView
for all provided SnowflakeCacheView implementations.static <E extends ISnowflake>
SnowflakeCacheView<E>allSnowflakes(java.util.function.Supplier<java.util.stream.Stream<SnowflakeCacheView<E>>> generator)
Creates a combinedSnowflakeCacheView
for all provided SnowflakeCacheView implementations.java.util.List<T>
asList()
Creates an immutable snapshot of the current cache state.java.util.Set<T>
asSet()
Creates an immutable snapshot of the current cache state.default <R,A>
Rcollect(java.util.stream.Collector<? super T,A,R> collector)
Collects all cached entities into a single Collection using the providedCollector
.default java.util.List<T>
getElementsByName(java.lang.String name)
Creates an immutable list of all elements matching the given name.java.util.List<T>
getElementsByName(java.lang.String name, boolean ignoreCase)
Creates an immutable list of all elements matching the given name.boolean
isEmpty()
Whether the cache is emptyjava.util.stream.Stream<T>
parallelStream()
Creates a parallelStream
of all cached elements.long
size()
The current size of this cache
This is along
as it may be a projected view of multiple caches (Seeall(java.util.function.Supplier)
)java.util.stream.Stream<T>
stream()
Creates aStream
of all cached elements.
-
-
-
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 aSortedSnowflakeCacheView
.- 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 along
as it may be a projected view of multiple caches (Seeall(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 emptyThis 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 aMemberCacheView
this will check theEffective Name
of the cached members.- Parameters:
name
- The name to checkignoreCase
- Whether to ignore case when comparing names- Returns:
- Immutable list of elements with the given name
- Throws:
java.lang.IllegalArgumentException
- If the provided name isnull
-
getElementsByName
default java.util.List<T> getElementsByName(java.lang.String name)
Creates an immutable list of all elements matching the given name.
For aMemberCacheView
this will check theEffective 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 isnull
-
stream
java.util.stream.Stream<T> stream()
Creates aStream
of all cached elements.
This will be sorted for aSortedSnowflakeCacheView
.- Returns:
- Stream of elements
-
parallelStream
java.util.stream.Stream<T> parallelStream()
Creates a parallelStream
of all cached elements.
This will be sorted for aSortedSnowflakeCacheView
.- 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 providedCollector
. Shortcut forstream().collect(collector)
.- Type Parameters:
R
- The output typeA
- The accumulator type- Parameters:
collector
- The collector used to collect the elements- Returns:
- Resulting collections
- Throws:
java.lang.IllegalArgumentException
- If the provided collector isnull
-
all
static <E> CacheView<E> all(java.util.Collection<? extends CacheView<E>> cacheViews)
Creates a combinedCacheView
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 ofCacheView
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 combinedCacheView
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 ofCacheView
implementations- Returns:
- Combined CacheView spanning over all provided implementation instances
-
allShards
static ShardCacheView allShards(java.util.Collection<ShardCacheView> cacheViews)
Creates a combinedShardCacheView
for all provided ShardCacheView implementations.- Parameters:
cacheViews
- Collection ofShardCacheView
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 combinedShardCacheView
for all provided ShardCacheView implementations.- Parameters:
generator
- Stream generator ofShardCacheView
implementations- Returns:
- Combined ShardCacheView spanning over all provided implementation instances
-
allSnowflakes
static <E extends ISnowflake> SnowflakeCacheView<E> allSnowflakes(java.util.Collection<SnowflakeCacheView<E>> cacheViews)
Creates a combinedSnowflakeCacheView
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 ofSnowflakeCacheView
implementations- Returns:
- Combined SnowflakeCacheView spanning over all provided implementation instances
-
allSnowflakes
static <E extends ISnowflake> SnowflakeCacheView<E> allSnowflakes(java.util.function.Supplier<java.util.stream.Stream<SnowflakeCacheView<E>>> generator)
Creates a combinedSnowflakeCacheView
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 ofSnowflakeCacheView
implementations- Returns:
- Combined SnowflakeCacheView spanning over all provided implementation instances
-
allMembers
static UnifiedMemberCacheView allMembers(java.util.Collection<MemberCacheView> cacheViews)
Creates a combinedUnifiedMemberCacheView
for all provided MemberCacheView implementations.
This allows to combine cache of multiple JDA sessions or Guilds.- Parameters:
cacheViews
- Collection ofMemberCacheView
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 combinedUnifiedMemberCacheView
for all provided MemberCacheView implementations.
This allows to combine cache of multiple JDA sessions or Guilds.- Parameters:
generator
- Stream generator ofMemberCacheView
instances- Returns:
- Combined MemberCacheView spanning over all provided instances
-
-