ArrayFromTuple implements Extractor<Tuple, Object[]> { @Override public Object[] extract(Tuple in) { Object[] output; if (order == null) { output = new Object[in.getArity()]; for (int i = 0; i < in.getArity(); i++) { output[i] = in.getField(i); } } else { output = new Object[order.length]; for (int i = 0; i < order.length; i++) { output[i] = in.getField(order[i]); } } return output; } ArrayFromTuple();  ArrayFromTuple(int... indexes); @Override Object[] extract(Tuple in);  }
@Test public void testConvertFromTupleToArray() throws InstantiationException, IllegalAccessException { for (int i = 0; i < Tuple.MAX_ARITY; i++) { Tuple currentTuple = (Tuple) CLASSES[i].newInstance(); String[] currentArray = new String[i + 1]; for (int j = 0; j <= i; j++) { currentTuple.setField(testStrings[j], j); currentArray[j] = testStrings[j]; } arrayEqualityCheck(currentArray, new ArrayFromTuple().extract(currentTuple)); } }
@Test public void testUserSpecifiedOrder() throws InstantiationException, IllegalAccessException { Tuple currentTuple = (Tuple) CLASSES[Tuple.MAX_ARITY - 1].newInstance(); for (int i = 0; i < Tuple.MAX_ARITY; i++) { currentTuple.setField(testStrings[i], i); } String[] expected = { testStrings[5], testStrings[3], testStrings[6], testStrings[7], testStrings[0] }; arrayEqualityCheck(expected, new ArrayFromTuple(5, 3, 6, 7, 0).extract(currentTuple)); String[] expected2 = { testStrings[0], testStrings[Tuple.MAX_ARITY - 1] }; arrayEqualityCheck(expected2, new ArrayFromTuple(0, Tuple.MAX_ARITY - 1).extract(currentTuple)); String[] expected3 = { testStrings[Tuple.MAX_ARITY - 1], testStrings[0] }; arrayEqualityCheck(expected3, new ArrayFromTuple(Tuple.MAX_ARITY - 1, 0).extract(currentTuple)); String[] expected4 = { testStrings[13], testStrings[4], testStrings[5], testStrings[4], testStrings[2], testStrings[8], testStrings[6], testStrings[2], testStrings[8], testStrings[3], testStrings[5], testStrings[2], testStrings[16], testStrings[4], testStrings[3], testStrings[2], testStrings[6], testStrings[4], testStrings[7], testStrings[4], testStrings[2], testStrings[8], testStrings[7], testStrings[2] }; arrayEqualityCheck(expected4, new ArrayFromTuple(13, 4, 5, 4, 2, 8, 6, 2, 8, 3, 5, 2, 16, 4, 3, 2, 6, 4, 7, 4, 2, 8, 7, 2).extract(currentTuple)); }