Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/ArrayHelper.java @ 658:d10399f80f4e
javac complained about casts, while eclipse compiler is fine
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Thu, 04 Jul 2013 21:09:33 +0200 |
| parents | 6334b0267103 |
| children | f568330dd9c0 |
comparison
equal
deleted
inserted
replaced
| 657:6334b0267103 | 658:d10399f80f4e |
|---|---|
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Slightly modified version of Arrays.sort1(int[], int, int) quicksort alg (just to deal with Object[]) | 110 * Slightly modified version of Arrays.sort1(int[], int, int) quicksort alg (just to deal with Object[]) |
| 111 */ | 111 */ |
| 112 private void sort1(int off, int len) { | 112 private void sort1(int off, int len) { |
| 113 @SuppressWarnings("unchecked") | 113 Comparable<Object>[] x = comparableSorted(); |
| 114 Comparable<Object>[] x = (Comparable<Object>[]) sorted; | |
| 115 // Insertion sort on smallest arrays | 114 // Insertion sort on smallest arrays |
| 116 if (len < 7) { | 115 if (len < 7) { |
| 117 for (int i=off; i<len+off; i++) | 116 for (int i=off; i<len+off; i++) |
| 118 for (int j=i; j>off && x[j-1].compareTo(x[j]) > 0; j--) | 117 for (int j=i; j>off && x[j-1].compareTo(x[j]) > 0; j--) |
| 119 swap(j, j-1); | 118 swap(j, j-1); |
| 176 | 175 |
| 177 /** | 176 /** |
| 178 * Returns the index of the median of the three indexed integers. | 177 * Returns the index of the median of the three indexed integers. |
| 179 */ | 178 */ |
| 180 private int med3(int a, int b, int c) { | 179 private int med3(int a, int b, int c) { |
| 181 @SuppressWarnings("unchecked") | 180 Comparable<Object>[] x = comparableSorted(); |
| 182 Comparable<Object>[] x = (Comparable<Object>[]) sorted; | |
| 183 return (x[a].compareTo(x[b]) < 0 ? | 181 return (x[a].compareTo(x[b]) < 0 ? |
| 184 (x[b].compareTo(x[c]) < 0 ? b : x[a].compareTo(x[c]) < 0 ? c : a) : | 182 (x[b].compareTo(x[c]) < 0 ? b : x[a].compareTo(x[c]) < 0 ? c : a) : |
| 185 (x[b].compareTo(x[c]) > 0 ? b : x[a].compareTo(x[c]) > 0 ? c : a)); | 183 (x[b].compareTo(x[c]) > 0 ? b : x[a].compareTo(x[c]) > 0 ? c : a)); |
| 184 } | |
| 185 | |
| 186 private Comparable<Object>[] comparableSorted() { | |
| 187 // Comparable<Object>[] x = (Comparable<Object>[]) sorted | |
| 188 // eclipse compiler is ok with the line above, while javac doesn't understand it: | |
| 189 // inconvertible types found : T[] required: java.lang.Comparable<java.lang.Object>[] | |
| 190 // so need to add another step | |
| 191 Comparable<?>[] oo = sorted; | |
| 192 @SuppressWarnings("unchecked") | |
| 193 Comparable<Object>[] x = (Comparable<Object>[]) oo; | |
| 194 return x; | |
| 186 } | 195 } |
| 187 | 196 |
| 188 /** | 197 /** |
| 189 * Swaps x[a] with x[b]. | 198 * Swaps x[a] with x[b]. |
| 190 */ | 199 */ |
