org.geotools.util
Class Ranks

Object
  extended by Ranks

public class Ranks
extends Object

Sorts elements in an array while remembering their ranks. Each method in this class sort the given array in the same way than Arrays.sort(Object[]) does, and in addition return the index that each element had in the original array prior the sorting.

Every methods are used in the same way:

 int[] index = ranks(source, target);
 
where source and target are arrays of Comparable elements or of a primitive type. The source argument is the array to sort and is left untouched (unless target is a reference to the same array). The target argument, if non-null, is the array where to store the sorted values.

The returned index array will have the same length than the source array. Each element in the returned array is an index ranging from 0 inclusive to source.length exclusive, such that target[i] = source[index[i]] for all i.

Invoking ranks(source, source) is equivalent to invoking Arrays.sort(source) in a less efficient way. The later should always be used (cloning the source array if needed) if the returned ranks are not used.

Since:
2.5
Author:
Martin Desruisseaux
Module:
modules/library/metadata (gt-metadata.jar)

Method Summary
static int[] ranks(byte[] source, byte[] target)
          Sorts the elements in the given array and return their ranks.
static int[] ranks(double[] source, double[] target)
          Sorts the elements in the given array and return their ranks.
static int[] ranks(float[] source, float[] target)
          Sorts the elements in the given array and return their ranks.
static int[] ranks(int[] source, int[] target)
          Sorts the elements in the given array and return their ranks.
static int[] ranks(long[] source, long[] target)
          Sorts the elements in the given array and return their ranks.
static int[] ranks(short[] source, short[] target)
          Sorts the elements in the given array and return their ranks.
static
<T extends Comparable<T>>
int[]
ranks(T[] source, T[] target)
          Sorts the elements in the given array and return their ranks.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

ranks

public static <T extends Comparable<T>> int[] ranks(T[] source,
                                                    T[] target)
Sorts the elements in the given array and return their ranks. See class description for details.

Type Parameters:
T - The type of elements in the array to be sorted.
Parameters:
source - The array of values to sort, or null.
target - The array where to store sorted values, or null if none. May be the same array than source, in which case the sorting will be performed in place.
Returns:
The value ranks, or null if source was null.
See Also:
Arrays.sort(Object[])

ranks

public static int[] ranks(double[] source,
                          double[] target)
Sorts the elements in the given array and return their ranks. See class description for details.

Parameters:
source - The array of values to sort, or null.
target - The array where to store sorted values, or null if none. May be the same array than source, in which case the sorting will be performed in place.
Returns:
The value ranks, or null if source was null.
See Also:
Arrays.sort(double[])

ranks

public static int[] ranks(float[] source,
                          float[] target)
Sorts the elements in the given array and return their ranks. See class description for details.

Parameters:
source - The array of values to sort, or null.
target - The array where to store sorted values, or null if none. May be the same array than source, in which case the sorting will be performed in place.
Returns:
The value ranks, or null if source was null.
See Also:
Arrays.sort(float[])

ranks

public static int[] ranks(long[] source,
                          long[] target)
Sorts the elements in the given array and return their ranks. See class description for details.

Parameters:
source - The array of values to sort, or null.
target - The array where to store sorted values, or null if none. May be the same array than source, in which case the sorting will be performed in place.
Returns:
The value ranks, or null if source was null.
See Also:
Arrays.sort(long[])

ranks

public static int[] ranks(int[] source,
                          int[] target)
Sorts the elements in the given array and return their ranks. See class description for details.

Parameters:
source - The array of values to sort, or null.
target - The array where to store sorted values, or null if none. May be the same array than source, in which case the sorting will be performed in place.
Returns:
The value ranks, or null if source was null.
See Also:
Arrays.sort(int[])

ranks

public static int[] ranks(short[] source,
                          short[] target)
Sorts the elements in the given array and return their ranks. See class description for details.

Parameters:
source - The array of values to sort, or null.
target - The array where to store sorted values, or null if none. May be the same array than source, in which case the sorting will be performed in place.
Returns:
The value ranks, or null if source was null.
See Also:
Arrays.sort(short[])

ranks

public static int[] ranks(byte[] source,
                          byte[] target)
Sorts the elements in the given array and return their ranks. See class description for details.

Parameters:
source - The array of values to sort, or null.
target - The array where to store sorted values, or null if none. May be the same array than source, in which case the sorting will be performed in place.
Returns:
The value ranks, or null if source was null.
See Also:
Arrays.sort(byte[])


Copyright © 1996-2009 Geotools. All Rights Reserved.