NonNullList.java
net.minecraft.core.NonNullList
信息
- 全限定名:net.minecraft.core.NonNullList
- 类型:public class
- 包:net.minecraft.core
- 源码路径:src/main/java/net/minecraft/core/NonNullList.java
- 起始行号:L10
- 继承:AbstractList
- 职责:
TODO
字段/常量
-
list- 类型:
List<E> - 修饰符:
private final - 源码定位:
L11 - 说明:
TODO
- 类型:
-
defaultValue- 类型:
E - 修饰符:
private final - 源码定位:
L12 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
protected NonNullList(List<E> list, E defaultValue) @ L34
- 构造器名:NonNullList
- 源码定位:L34
- 修饰符:protected
参数:
- list: List
- defaultValue: E
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static <E> NonNullList<E> create() @ L14
- 方法名:create
- 源码定位:L14
- 返回类型:
NonNullList - 修饰符:public static
参数:
- 无
说明:
TODO
public static <E> NonNullList<E> createWithCapacity(int capacity) @ L18
- 方法名:createWithCapacity
- 源码定位:L18
- 返回类型:
NonNullList - 修饰符:public static
参数:
- capacity: int
说明:
TODO
public static <E> NonNullList<E> withSize(int size, E defaultValue) @ L22
- 方法名:withSize
- 源码定位:L22
- 返回类型:
NonNullList - 修饰符:public static
参数:
- size: int
- defaultValue: E
说明:
TODO
public static <E> NonNullList<E> of(E defaultValue, E... values) @ L29
- 方法名:of
- 源码定位:L29
- 返回类型:
NonNullList - 修饰符:public static
参数:
- defaultValue: E
- values: E…
说明:
TODO
public E get(int index) @ L39
- 方法名:get
- 源码定位:L39
- 返回类型:E
- 修饰符:public
参数:
- index: int
说明:
TODO
public E set(int index, E element) @ L44
- 方法名:set
- 源码定位:L44
- 返回类型:E
- 修饰符:public
参数:
- index: int
- element: E
说明:
TODO
public void add(int index, E element) @ L50
- 方法名:add
- 源码定位:L50
- 返回类型:void
- 修饰符:public
参数:
- index: int
- element: E
说明:
TODO
public E remove(int index) @ L56
- 方法名:remove
- 源码定位:L56
- 返回类型:E
- 修饰符:public
参数:
- index: int
说明:
TODO
public int size() @ L61
- 方法名:size
- 源码定位:L61
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public void clear() @ L66
- 方法名:clear
- 源码定位:L66
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class NonNullList<E> extends AbstractList<E> {
private final List<E> list;
private final @Nullable E defaultValue;
public static <E> NonNullList<E> create() {
return new NonNullList<>(Lists.newArrayList(), null);
}
public static <E> NonNullList<E> createWithCapacity(int capacity) {
return new NonNullList<>(Lists.newArrayListWithCapacity(capacity), null);
}
public static <E> NonNullList<E> withSize(int size, E defaultValue) {
Objects.requireNonNull(defaultValue);
Object[] objects = new Object[size];
Arrays.fill(objects, defaultValue);
return new NonNullList<>(Arrays.asList((E[])objects), defaultValue);
}
@SafeVarargs
public static <E> NonNullList<E> of(E defaultValue, E... values) {
return new NonNullList<>(Arrays.asList(values), defaultValue);
}
protected NonNullList(List<E> list, @Nullable E defaultValue) {
this.list = list;
this.defaultValue = defaultValue;
}
@Override
public E get(int index) {
return this.list.get(index);
}
@Override
public E set(int index, E element) {
Objects.requireNonNull(element);
return this.list.set(index, element);
}
@Override
public void add(int index, E element) {
Objects.requireNonNull(element);
this.list.add(index, element);
}
@Override
public E remove(int index) {
return this.list.remove(index);
}
@Override
public int size() {
return this.list.size();
}
@Override
public void clear() {
if (this.defaultValue == null) {
super.clear();
} else {
for (int i = 0; i < this.size(); i++) {
this.set(i, this.defaultValue);
}
}
}
}引用的其他类
- 无