PredictionContext instances are not naturally ordered, so remove Comparable implementation

This commit is contained in:
Sam Harwell 2013-06-06 15:44:38 -05:00
parent 4c45a4bc66
commit 84324f1dad
1 changed files with 8 additions and 8 deletions

View File

@ -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<PredictionContext> // 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<PredictionContext>
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<PredictionContext>
buf.append("rankdir=LR;\n");
List<PredictionContext> nodes = getAllContextNodes(context);
Collections.sort(nodes);
Collections.sort(nodes, new Comparator<PredictionContext>() {
@Override
public int compare(PredictionContext o1, PredictionContext o2) {
return o1.id - o2.id;
}
});
for (PredictionContext current : nodes) {
if ( current instanceof SingletonPredictionContext ) {