package net.minecraft.advancements.predicates; 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(final Codec

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

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

tests) implements CollectionContentsPredicate { public boolean test(final Iterable values) { List> 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

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

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

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