Regid fixes

This commit is contained in:
cyberpwn 2021-08-25 02:42:01 -04:00
parent babefc7bd3
commit 62f6917d81

View File

@ -22,6 +22,7 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
@ -29,54 +30,42 @@ import java.util.List;
public class RegistryBlockID<T> implements Registry<T> {
public static final int a = -1;
private int b;
private final IdentityHashMap<T, Integer> c;
private final List<T> d;
private final HashMap<T, Integer> indexMap;
private final List<T> indexes;
public RegistryBlockID(IdentityHashMap<T, Integer> c, List<T> d, int b) {
this.indexMap = new HashMap<>(c);
this.indexes = d;
this.b = b;
}
public RegistryBlockID() {
this(512);
}
public RegistryBlockID(int var0) {
this.d = Lists.newArrayListWithExpectedSize(var0);
this.c = new IdentityHashMap(var0);
}
public void a(T var0, int var1) {
this.c.put(var0, var1);
while (this.d.size() <= var1) {
this.d.add(null);
}
this.d.set(var1, var0);
if (this.b <= var1) {
this.b = var1 + 1;
}
}
public void b(T var0) {
this.a(var0, this.b);
this.indexes = Lists.newArrayListWithExpectedSize(var0);
this.indexMap = new HashMap<>(var0);
}
public int getId(T var0) {
Integer var1 = (Integer) this.c.get(var0);
Integer var1 = this.indexMap.get(var0);
return var1 == null ? -1 : var1;
}
public final T fromId(int var0) {
return var0 >= 0 && var0 < this.d.size() ? this.d.get(var0) : null;
return var0 >= 0 && var0 < this.indexes.size() ? this.indexes.get(var0) : null;
}
public Iterator<T> iterator() {
return Iterators.filter(this.d.iterator(), Predicates.notNull());
return Iterators.filter(this.indexes.iterator(), Predicates.notNull());
}
public boolean b(int var0) {
public boolean hasIndex(int var0) {
return this.fromId(var0) != null;
}
public int a() {
return this.c.size();
public int size() {
return this.indexMap.size();
}
}