IdMapper.java
net.minecraft.core.IdMapper
信息
- 全限定名:net.minecraft.core.IdMapper
- 类型:public class
- 包:net.minecraft.core
- 源码路径:src/main/java/net/minecraft/core/IdMapper.java
- 起始行号:L12
- 实现:IdMap
- 职责:
TODO
字段/常量
-
nextId- 类型:
int - 修饰符:
private - 源码定位:
L13 - 说明:
TODO
- 类型:
-
tToId- 类型:
Reference2IntMap<T> - 修饰符:
private final - 源码定位:
L14 - 说明:
TODO
- 类型:
-
idToT- 类型:
List<T> - 修饰符:
private final - 源码定位:
L15 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public IdMapper() @ L17
- 构造器名:IdMapper
- 源码定位:L17
- 修饰符:public
参数:
- 无
说明:
TODO
public IdMapper(int expectedSize) @ L21
- 构造器名:IdMapper
- 源码定位:L21
- 修饰符:public
参数:
- expectedSize: int
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void addMapping(T thing, int id) @ L27
- 方法名:addMapping
- 源码定位:L27
- 返回类型:void
- 修饰符:public
参数:
- thing: T
- id: int
说明:
TODO
public void add(T thing) @ L40
- 方法名:add
- 源码定位:L40
- 返回类型:void
- 修饰符:public
参数:
- thing: T
说明:
TODO
public int getId(T thing) @ L44
- 方法名:getId
- 源码定位:L44
- 返回类型:int
- 修饰符:public
参数:
- thing: T
说明:
TODO
public final T byId(int id) @ L49
- 方法名:byId
- 源码定位:L49
- 返回类型:T
- 修饰符:public final
参数:
- id: int
说明:
TODO
public Iterator<T> iterator() @ L54
- 方法名:iterator
- 源码定位:L54
- 返回类型:Iterator
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean contains(int id) @ L59
- 方法名:contains
- 源码定位:L59
- 返回类型:boolean
- 修饰符:public
参数:
- id: int
说明:
TODO
public int size() @ L63
- 方法名:size
- 源码定位:L63
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class IdMapper<T> implements IdMap<T> {
private int nextId;
private final Reference2IntMap<T> tToId;
private final List<T> idToT;
public IdMapper() {
this(512);
}
public IdMapper(int expectedSize) {
this.idToT = Lists.newArrayListWithExpectedSize(expectedSize);
this.tToId = new Reference2IntOpenHashMap<>(expectedSize);
this.tToId.defaultReturnValue(-1);
}
public void addMapping(T thing, int id) {
this.tToId.put(thing, id);
while (this.idToT.size() <= id) {
this.idToT.add(null);
}
this.idToT.set(id, thing);
if (this.nextId <= id) {
this.nextId = id + 1;
}
}
public void add(T thing) {
this.addMapping(thing, this.nextId);
}
@Override
public int getId(T thing) {
return this.tToId.getInt(thing);
}
@Override
public final @Nullable T byId(int id) {
return id >= 0 && id < this.idToT.size() ? this.idToT.get(id) : null;
}
@Override
public Iterator<T> iterator() {
return Iterators.filter(this.idToT.iterator(), Objects::nonNull);
}
public boolean contains(int id) {
return this.byId(id) != null;
}
@Override
public int size() {
return this.tToId.size();
}
}引用的其他类
- IdMap
- 引用位置:
实现
- 引用位置: