package net.minecraft.util.parsing.packrat; import java.util.ArrayList; import java.util.List; public interface ErrorCollector { void store(int cursor, SuggestionSupplier suggestions, Object reason); default void store(int cursor, Object reason) { this.store(cursor, SuggestionSupplier.empty(), reason); } void finish(int cursor); public static class LongestOnly implements ErrorCollector { private final List> entries = new ArrayList(); private int lastCursor = -1; private void discardErrorsFromShorterParse(int cursor) { if (cursor > this.lastCursor) { this.lastCursor = cursor; this.entries.clear(); } } @Override public void finish(int cursor) { this.discardErrorsFromShorterParse(cursor); } @Override public void store(int cursor, SuggestionSupplier suggestions, Object reason) { this.discardErrorsFromShorterParse(cursor); if (cursor == this.lastCursor) { this.entries.add(new ErrorEntry<>(cursor, suggestions, reason)); } } public List> entries() { return this.entries; } public int cursor() { return this.lastCursor; } } }