X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/TwoArrayQuickSorter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/TwoArrayQuickSorter.java index bf8bb1b..86db922 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/TwoArrayQuickSorter.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/TwoArrayQuickSorter.java @@ -5,11 +5,11 @@ import java.util.Comparator; import org.eclipse.jface.util.Assert; /** - * Quick sort to sort key-value pairs. The keys and arrays are specified - * in separate arrays. + * Quick sort to sort key-value pairs. The keys and arrays are specified in + * separate arrays. */ public class TwoArrayQuickSorter { - + private Comparator fComparator; /** @@ -17,39 +17,47 @@ public class TwoArrayQuickSorter { */ public static final class StringComparator implements Comparator { private boolean fIgnoreCase; - + StringComparator(boolean ignoreCase) { - fIgnoreCase= ignoreCase; + fIgnoreCase = ignoreCase; } - + public int compare(Object left, Object right) { - return fIgnoreCase - ? ((String) left).compareToIgnoreCase((String) right) - : ((String) left).compareTo((String) right); + return fIgnoreCase ? ((String) left) + .compareToIgnoreCase((String) right) : ((String) left) + .compareTo((String) right); } - } + } /** - * Creates a sorter with default string comparator. - * The keys are assumed to be strings. - * @param ignoreCase specifies whether sorting is case sensitive or not. - */ + * Creates a sorter with default string comparator. The keys are assumed to + * be strings. + * + * @param ignoreCase + * specifies whether sorting is case sensitive or not. + */ public TwoArrayQuickSorter(boolean ignoreCase) { - fComparator= new StringComparator(ignoreCase); + fComparator = new StringComparator(ignoreCase); } /** * Creates a sorter with a comparator. - * @param comparator the comparator to order the elements. The comparator must not be null. + * + * @param comparator + * the comparator to order the elements. The comparator must not + * be null. */ public TwoArrayQuickSorter(Comparator comparator) { - fComparator= comparator; + fComparator = comparator; } - + /** * Sorts keys and values in parallel. - * @param keys the keys to use for sorting. - * @param values the values associated with the keys. + * + * @param keys + * the keys to use for sorting. + * @param values + * the values associated with the keys. */ public void sort(Object[] keys, Object[] values) { if ((keys == null) || (values == null)) { @@ -59,44 +67,45 @@ public class TwoArrayQuickSorter { if (keys.length <= 1) return; - - internalSort(keys, values, 0, keys.length - 1); + + internalSort(keys, values, 0, keys.length - 1); } - private void internalSort(Object[] keys, Object[] values, int left, int right) { - int original_left= left; - int original_right= right; - - Object mid= keys[(left + right) / 2]; - do { + private void internalSort(Object[] keys, Object[] values, int left, + int right) { + int original_left = left; + int original_right = right; + + Object mid = keys[(left + right) / 2]; + do { while (fComparator.compare(keys[left], mid) < 0) - left++; + left++; while (fComparator.compare(mid, keys[right]) < 0) - right--; + right--; if (left <= right) { swap(keys, left, right); swap(values, left, right); - left++; - right--; - } + left++; + right--; + } } while (left <= right); - + if (original_left < right) - internalSort(keys , values, original_left, right); + internalSort(keys, values, original_left, right); if (left < original_right) - internalSort(keys, values, left, original_right); + internalSort(keys, values, left, original_right); } - /* - * Swaps x[a] with x[b]. - */ - private static final void swap(Object x[], int a, int b) { + /* + * Swaps x[a] with x[b]. + */ + private static final void swap(Object x[], int a, int b) { Object t = x[a]; x[a] = x[b]; x[b] = t; - } - + } + } \ No newline at end of file