package net.minecraft.client.searchtree; import java.util.List; import java.util.Locale; import java.util.function.Function; import java.util.stream.Stream; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @FunctionalInterface @Environment(EnvType.CLIENT) public interface SearchTree { static SearchTree empty() { return string -> List.of(); } static SearchTree plainText(List list, Function> function) { if (list.isEmpty()) { return empty(); } else { SuffixArray suffixArray = new SuffixArray<>(); for (T object : list) { ((Stream)function.apply(object)).forEach(string -> suffixArray.add(object, string.toLowerCase(Locale.ROOT))); } suffixArray.generate(); return suffixArray::search; } } /** * Searches this search tree for the given text. *

* If the query does not contain a {@code :}, then only {@link #byName} is searched. If it does contain a colon, both {@link #byName} and {@link #byId} are searched and the results are merged using a {@link MergingIterator}. * @return A list of all matching items in this search tree. */ List search(String query); }