package net.minecraft.advancements.critereon; import com.mojang.serialization.Codec; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; public interface CollectionContentsPredicate> extends Predicate> { List

unpack(); static > Codec> codec(Codec

testCodec) { return testCodec.listOf().xmap(CollectionContentsPredicate::of, CollectionContentsPredicate::unpack); } @SafeVarargs static > CollectionContentsPredicate of(P... tests) { return of(List.of(tests)); } static > CollectionContentsPredicate of(List

tests) { return (CollectionContentsPredicate)(switch (tests.size()) { case 0 -> new CollectionContentsPredicate.Zero(); case 1 -> new CollectionContentsPredicate.Single((P)tests.getFirst()); default -> new CollectionContentsPredicate.Multiple(tests); }); } public record Multiple>(List

tests) implements CollectionContentsPredicate { public boolean test(Iterable contents) { List> list = new ArrayList(this.tests); for (T object : contents) { list.removeIf(predicate -> predicate.test(object)); if (list.isEmpty()) { return true; } } return false; } @Override public List

unpack() { return this.tests; } } public record Single>(P test) implements CollectionContentsPredicate { public boolean test(Iterable contents) { for (T object : contents) { if (this.test.test(object)) { return true; } } return false; } @Override public List

unpack() { return List.of(this.test); } } public static class Zero> implements CollectionContentsPredicate { public boolean test(Iterable contents) { return true; } @Override public List

unpack() { return List.of(); } } }