Add a method on Registry to get the size (#12182)

This commit is contained in:
Glicz
2025-02-25 22:02:48 +01:00
committed by GitHub
parent 5f2ee83ed4
commit b00875f86d
3 changed files with 33 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
@@ -297,6 +298,11 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return MemoryKey.values().iterator();
}
@Override
public int size() {
return MemoryKey.values().size();
}
@Override
public @Nullable MemoryKey get(final NamespacedKey key) {
return MemoryKey.getByKey(key);
@@ -536,6 +542,13 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return (namespacedKey != null) ? this.get(namespacedKey) : null;
}
/**
* Gets the size of the registry.
*
* @return the size of the registry
*/
int size();
@ApiStatus.Internal
class SimpleRegistry<T extends Enum<T> & Keyed> extends NotARegistry<T> { // Paper - remove final
@@ -564,6 +577,11 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return this.map.get(key);
}
@Override
public int size() {
return map.size();
}
@Override
public Iterator<T> iterator() {
return this.map.values().iterator();
@@ -584,6 +602,11 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return StreamSupport.stream(this.spliterator(), false);
}
@Override
public int size() {
return Iterables.size(this);
}
@Override
public NamespacedKey getKey(final A value) {
return value.getKey();