Files
AkarinMC/src/main/java/net/minecraft/server/RegistryBlockID.java
2019-03-04 22:48:32 +08:00

66 lines
1.8 KiB
Java

package net.minecraft.server;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.koloboke.collect.map.hash.HashObjIntMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nullable;
public class RegistryBlockID<T> implements Registry<T> {
private int a;
private final HashObjIntMap<T> b; // Akarin - IdentityHashMap -> HashObjIntMap
private final List<T> c;
public RegistryBlockID() {
this(512);
}
public RegistryBlockID(int i) {
this.c = Lists.newArrayListWithExpectedSize(i);
this.b = com.koloboke.collect.map.hash.HashObjIntMaps.getDefaultFactory().withHashConfig(com.koloboke.collect.hash.HashConfig.fromLoads(1./3., 2./3., 2./3.)).withNullKeyAllowed(true).withKeyEquivalence(com.koloboke.collect.Equivalence.identity()).newUpdatableMap(i); // Akarin - koloboke
}
public void a(T t0, int i) {
this.b.put(t0, i);
while (this.c.size() <= i) {
this.c.add(null); // Paper - decompile fix
}
this.c.set(i, t0);
if (this.a <= i) {
this.a = i + 1;
}
}
public void b(T t0) {
this.a(t0, this.a);
}
public int getId(T t0) {
Integer integer = (Integer) this.b.get(t0);
return integer == null ? -1 : integer;
}
@Nullable
public final T fromId(int i) {
return i >= 0 && i < this.c.size() ? this.c.get(i) : null;
}
public Iterator<T> iterator() {
return Iterators.filter(this.c.iterator(), Predicates.notNull());
}
public int size() { return this.a(); } // Paper - OBFHELPER
public int a() {
return this.b.size();
}
}