Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dmitrygusev
Created January 14, 2012 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitrygusev/1610889 to your computer and use it in GitHub Desktop.
Save dmitrygusev/1610889 to your computer and use it in GitHub Desktop.
SSF4J Usage
package com.anjlab.ssf4j;
import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
public class SortHandlerTest {
@Test
public void testSort() {
final String[] names = new String[] { "Three", "One", "Two", "Zero" };
final int[] weights = new int[] { 3, 1, 2, 0 };
SortHandler<Integer> handler =
new SortHandler<Integer>() {
public int from() {
return 0;
}
public int to() {
return weights.length - 1;
}
public Integer get(int index) {
return weights[index];
}
public int compare(Integer a, Integer b) {
return b - a;
}
public void swap(int i, int j) {
Utils.swap(weights, i, j);
Utils.swap(names, i, j);
}
};
handler.sort();
assertArrayEquals(new String[] { "Zero", "One", "Two", "Three" }, names);
assertArrayEquals(new int[] { 0, 1, 2, 3 }, weights);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment