diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java index e6d89b0f6..1ddcf5d2d 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java @@ -40,13 +40,13 @@ import org.antlr.v4.runtime.misc.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; -public abstract class PredictionContext implements Comparable // to sort node lists by id -{ +public abstract class PredictionContext { /** * Represents {@code $} in local context prediction, which means wildcard. * {@code *+x = *}. @@ -130,11 +130,6 @@ public abstract class PredictionContext implements Comparable return getReturnState(size() - 1) == EMPTY_RETURN_STATE; } - @Override - public int compareTo(PredictionContext o) { // used for toDotString to print nodes in order - return id - o.id; - } - @Override public final int hashCode() { return cachedHashCode; @@ -550,7 +545,12 @@ public abstract class PredictionContext implements Comparable buf.append("rankdir=LR;\n"); List nodes = getAllContextNodes(context); - Collections.sort(nodes); + Collections.sort(nodes, new Comparator() { + @Override + public int compare(PredictionContext o1, PredictionContext o2) { + return o1.id - o2.id; + } + }); for (PredictionContext current : nodes) { if ( current instanceof SingletonPredictionContext ) {