CollectionContentsPredicate.java
net.minecraft.advancements.criterion.CollectionContentsPredicate
信息
- 全限定名:net.minecraft.advancements.criterion.CollectionContentsPredicate
- 类型:public interface
- 包:net.minecraft.advancements.criterion
- 源码路径:src/main/java/net/minecraft/advancements/criterion/CollectionContentsPredicate.java
- 起始行号:L8
- 继承:Predicate<Iterable<?extends T>>
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
-
net.minecraft.advancements.criterion.CollectionContentsPredicate.Multiple- 类型:
record - 修饰符:
public - 源码定位:
L28 - 说明:
TODO
- 类型:
-
net.minecraft.advancements.criterion.CollectionContentsPredicate.Single- 类型:
record - 修饰符:
public - 源码定位:
L48 - 说明:
TODO
- 类型:
-
net.minecraft.advancements.criterion.CollectionContentsPredicate.Zero- 类型:
class - 修饰符:
public static - 源码定位:
L65 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
List<P> unpack() @ L9
- 方法名:unpack
- 源码定位:L9
- 返回类型:List
- 修饰符:package-private
参数:
- 无
说明:
TODO
static <T,P extends Predicate<T>> Codec<CollectionContentsPredicate<T,P>> codec(Codec<P> elementCodec) @ L11
- 方法名:codec
- 源码定位:L11
- 返回类型:<T,P extends Predicate
> Codec<CollectionContentsPredicate<T,P>> - 修饰符:static
参数:
- elementCodec: Codec
说明:
TODO
static <T,P extends Predicate<T>> CollectionContentsPredicate<T,P> of(P... predicates) @ L15
- 方法名:of
- 源码定位:L15
- 返回类型:<T,P extends Predicate
> CollectionContentsPredicate<T,P> - 修饰符:static
参数:
- predicates: P…
说明:
TODO
static <T,P extends Predicate<T>> CollectionContentsPredicate<T,P> of(List<P> predicates) @ L20
- 方法名:of
- 源码定位:L20
- 返回类型:<T,P extends Predicate
> CollectionContentsPredicate<T,P> - 修饰符:static
参数:
- predicates: List
说明:
TODO
代码
public interface CollectionContentsPredicate<T, P extends Predicate<T>> extends Predicate<Iterable<? extends T>> {
List<P> unpack();
static <T, P extends Predicate<T>> Codec<CollectionContentsPredicate<T, P>> codec(Codec<P> elementCodec) {
return elementCodec.listOf().xmap(CollectionContentsPredicate::of, CollectionContentsPredicate::unpack);
}
@SafeVarargs
static <T, P extends Predicate<T>> CollectionContentsPredicate<T, P> of(P... predicates) {
return of(List.of(predicates));
}
static <T, P extends Predicate<T>> CollectionContentsPredicate<T, P> of(List<P> predicates) {
return (CollectionContentsPredicate<T, P>)(switch (predicates.size()) {
case 0 -> new CollectionContentsPredicate.Zero();
case 1 -> new CollectionContentsPredicate.Single(predicates.getFirst());
default -> new CollectionContentsPredicate.Multiple(predicates);
});
}
public record Multiple<T, P extends Predicate<T>>(List<P> tests) implements CollectionContentsPredicate<T, P> {
public boolean test(Iterable<? extends T> values) {
List<Predicate<T>> testsToMatch = new ArrayList<>(this.tests);
for (T value : values) {
testsToMatch.removeIf(p -> p.test(value));
if (testsToMatch.isEmpty()) {
return true;
}
}
return false;
}
@Override
public List<P> unpack() {
return this.tests;
}
}
public record Single<T, P extends Predicate<T>>(P test) implements CollectionContentsPredicate<T, P> {
public boolean test(Iterable<? extends T> values) {
for (T value : values) {
if (this.test.test(value)) {
return true;
}
}
return false;
}
@Override
public List<P> unpack() {
return List.of(this.test);
}
}
public static class Zero<T, P extends Predicate<T>> implements CollectionContentsPredicate<T, P> {
public boolean test(Iterable<? extends T> values) {
return true;
}
@Override
public List<P> unpack() {
return List.of();
}
}
}引用的其他类
- 无