Permalink
Browse files

Make Ioke work on both Java 6 and Java 7 by implementing my custom so…

…rt to handle partial ordering of Java methods
  • Loading branch information...
1 parent 992a24d commit c5f345b3983a95f3e5725d07ff5b4e02afc860e4 @olabini committed Jul 19, 2011
Showing with 15 additions and 2 deletions.
  1. +15 −2 src/ikj/main/ioke/lang/JavaArgumentsDefinition.java
@@ -144,12 +144,25 @@ public int compare(Constructor a, Constructor b) {
}
}
+ public static <T> void partialOrderingSort(T[] arr, Comparator<T> c) {
+ int count = arr.length;
+ for(int j = 1; j < count; j++) {
+ T key = arr[j];
+ int i = j - 1;
+ for(; i >= 0 && c.compare(arr[i], key) > 0; i--) {
+ arr[i + 1] = arr[i];
+ }
+ arr[i + 1] = key;
+ }
+ }
+
+
private static void sortByParameterOrdering(Method[] m) {
// System.err.println("Before sort: ");
// for(Method mex : m) {
// System.err.println(" - " + mex);
// }
- Arrays.sort(m, new MethodComparator());
+ partialOrderingSort(m, new MethodComparator());
// System.err.println("After sort: ");
// for(Method mex : m) {
// System.err.println(" - " + mex);
@@ -161,7 +174,7 @@ private static void sortByParameterOrdering(Constructor[] m) {
// for(Constructor mex : m) {
// System.err.println(" - " + mex);
// }
- Arrays.sort(m, new ConstructorComparator());
+ partialOrderingSort(m, new ConstructorComparator());
// System.err.println("After sort: ");
// for(Constructor mex : m) {
// System.err.println(" - " + mex);

0 comments on commit c5f345b

Please sign in to comment.