/** Construct a column mapping that maps the input (one col, one char) to the output */ public ColumnMap(String input, String output) { this(input+"->"+output, compileMapping(input, output)) ; }
public <T> ColumnMap(String label, List<T> input, List<T> output) { this(label, compileMapping(input, output)) ; }
public <T> ColumnMap(String label, T[] input, T[] output) { this(label, compileMapping(input, output)) ; }
/** Compile a mapping, encoded two list, the domain and range of the mapping function */ static <T> int[] compileMapping(T[] domain, T[] range) { return compileMapping(Arrays.asList(domain), Arrays.asList(range)) ; }
/** Compile a mapping encoded as single characters e.g. "SPO", "POS" */ static int[] compileMapping(String domain, String range) { List<Character> input = StrUtils.toCharList(domain) ; List<Character> output = StrUtils.toCharList(range) ; return compileMapping(input, output) ; }
@Test public void compile1() { int[] x = ColumnMap.compileMapping("SPO", "POS") ; // SPO -> POS so col 0 goes to col 2, col 1 goes to col 0 and col 2 goes to col 1 int[] expected = { 2,0,1 } ; assertArrayEquals(expected, x) ; }
@Test public void compile2() { int[] x = ColumnMap.compileMapping("SPOG", "GOPS") ; int[] expected = { 3, 2, 1, 0 } ; assertArrayEquals(expected, x) ; }
@Test public void compile1() { int[] x = ColumnMap.compileMapping("SPO", "POS") ; // SPO -> POS so col 0 goes to col 2, col 1 goes to col 0 and col 2 goes to col 1 int[] expected = { 2,0,1 } ; assertArrayEquals(expected, x) ; }
@Test public void compile2() { int[] x = ColumnMap.compileMapping("SPOG", "GOPS") ; int[] expected = { 3, 2, 1, 0 } ; assertArrayEquals(expected, x) ; }