mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-03 13:42:25 -07:00
Add a method on Registry to get the size (#12182)
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user