From bb2af1d8839029e65f8252b5e2eb09a6bfa2100c Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Thu, 10 May 2012 15:48:26 -0400 Subject: [PATCH] Tweak ordering for sorting- should be a stable sort now --- fml/client/net/minecraft/src/BaseMod.java | 2 +- .../fml/common/toposort/TopologicalSort.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/fml/client/net/minecraft/src/BaseMod.java b/fml/client/net/minecraft/src/BaseMod.java index 5036c0af2..e21b2b465 100644 --- a/fml/client/net/minecraft/src/BaseMod.java +++ b/fml/client/net/minecraft/src/BaseMod.java @@ -212,7 +212,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp */ public String getPriorities() { - return null; + return ""; } /** diff --git a/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java b/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java index 2eafae234..f3a03ae1d 100644 --- a/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java +++ b/fml/common/cpw/mods/fml/common/toposort/TopologicalSort.java @@ -15,6 +15,7 @@ package cpw.mods.fml.common.toposort; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -22,6 +23,8 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; /** * Topological sort for mod loading @@ -34,8 +37,9 @@ public class TopologicalSort { public static class DirectedGraph implements Iterable { - private final Map> graph = new HashMap>(); - + private final Map> graph = new HashMap>(); + private List orderedNodes = new ArrayList(); + public boolean addNode(T node) { // Ignore nodes already added @@ -44,7 +48,13 @@ public class TopologicalSort return false; } - graph.put(node, new HashSet()); + orderedNodes.add(node); + graph.put(node, new TreeSet(new Comparator() + { + public int compare(T o1, T o2) { + return orderedNodes.indexOf(o1)-orderedNodes.indexOf(o2); + } + })); return true; } @@ -85,12 +95,12 @@ public class TopologicalSort throw new NoSuchElementException("Missing node from graph"); } - return Collections.unmodifiableSet(graph.get(from)); + return Collections.unmodifiableSortedSet(graph.get(from)); } @Override public Iterator iterator() { - return graph.keySet().iterator(); + return orderedNodes.iterator(); } public int size()