jml.utils
Class Utility.ArrayIndexComparator<V extends java.lang.Comparable<? super V>>
java.lang.Object
jml.utils.Utility.ArrayIndexComparator<V>
- Type Parameters:
V
- Class type that extends the Comparable
interface.
- All Implemented Interfaces:
- java.util.Comparator<java.lang.Integer>
- Enclosing class:
- Utility
public static class Utility.ArrayIndexComparator<V extends java.lang.Comparable<? super V>>
- extends java.lang.Object
- implements java.util.Comparator<java.lang.Integer>
A generic Class
that implements Comparator which provide
a override comparator function sorting a array's indices based on its values.
Usage:
String[] countries = { "France", "Spain", ... };
ArrayIndexComparator comparator = new ArrayIndexComparator(countries);
Integer[] idxVector = comparator.createIndexArray();
Arrays.sort(idxVector, comparator);
Now the indexes are in appropriate order.
Field Summary |
private V[] |
array
|
Method Summary |
int |
compare(java.lang.Integer index1,
java.lang.Integer index2)
|
java.lang.Integer[] |
createIndexArray()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Comparator |
equals |
array
private final V extends java.lang.Comparable<? super V>[] array
Utility.ArrayIndexComparator
public Utility.ArrayIndexComparator(V[] array)
createIndexArray
public java.lang.Integer[] createIndexArray()
compare
public int compare(java.lang.Integer index1,
java.lang.Integer index2)
- Specified by:
compare
in interface java.util.Comparator<java.lang.Integer>