RandomKey extends AbstractListChromosome<Double> implements PermutationChromosome<T> { public static <S> List<Double> comparatorPermutation(final List<S> data, final Comparator<S> comparator) { List<S> sortedData = new ArrayList<S>(data); Collections.sort(sortedData, comparator); return inducedPermutation(data, sortedData); } RandomKey(final List<Double> representation);  RandomKey(final Double[] representation); List<T> decode(final List<T> sequence); static final List<Double> randomPermutation(final int l); static final List<Double> identityPermutation(final int l); static List<Double> comparatorPermutation(final List<S> data,
                                                         final Comparator<S> comparator); static List<Double> inducedPermutation(final List<S> originalData,
                                                      final List<S> permutedData); @Override String toString();  }
@Test public void testComparatorPermutation() { List<String> data = Arrays.asList(new String[] {"x", "b", "c", "z", "b"}); List<Double> permutation = RandomKey.comparatorPermutation(data, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareTo(o2); } }); Double[] permArr = new Double[data.size()]; permArr = permutation.toArray(permArr); Assert.assertArrayEquals(new Double[] {0.6,0.0,0.4,0.8,0.2}, permArr); List<String> decodedData = new DummyRandomKey(permutation).decode(data); Assert.assertEquals("b", decodedData.get(0)); Assert.assertEquals("b", decodedData.get(1)); Assert.assertEquals("c", decodedData.get(2)); Assert.assertEquals("x", decodedData.get(3)); Assert.assertEquals("z", decodedData.get(4)); permutation = RandomKey.comparatorPermutation(data, new Comparator<String>() { public int compare(String o1, String o2) { return o2.compareTo(o1); } }); permArr = new Double[data.size()]; permArr = permutation.toArray(permArr); Assert.assertArrayEquals(new Double[] {0.2,0.6,0.4,0.0,0.8}, permArr); decodedData = new DummyRandomKey(permutation).decode(data); Assert.assertEquals("z", decodedData.get(0)); Assert.assertEquals("x", decodedData.get(1)); Assert.assertEquals("c", decodedData.get(2)); Assert.assertEquals("b", decodedData.get(3)); Assert.assertEquals("b", decodedData.get(4)); }