Add keyStream() API to registries (#12479)

This commit is contained in:
Maddy Miller
2025-04-25 22:26:56 +10:00
committed by GitHub
parent 3409e2d73f
commit 1cfc96bcf7
3 changed files with 28 additions and 0 deletions

View File

@@ -525,6 +525,13 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
*/
Stream<T> stream();
/**
* Returns a new stream, which contains all registry keys, which are registered to the registry.
*
* @return a stream of all registry keys
*/
Stream<NamespacedKey> keyStream();
/**
* Attempts to match the registered object with the given key.
* <p>
@@ -591,6 +598,11 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return this.map.values().iterator();
}
@Override
public Stream<NamespacedKey> keyStream() {
return this.map.keySet().stream();
}
@ApiStatus.Internal
@Deprecated(since = "1.20.6", forRemoval = true)
public Class<T> getType() {
@@ -606,6 +618,11 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return StreamSupport.stream(this.spliterator(), false);
}
@Override
public Stream<NamespacedKey> keyStream() {
return stream().map(this::getKey);
}
@Override
public int size() {
return Iterables.size(this);