FieldsFromArray implements Extractor<Object, OUT[]> { @SuppressWarnings("unchecked") @Override public OUT[] extract(Object in) { OUT[] output = (OUT[]) Array.newInstance(clazz, order.length); for (int i = 0; i < order.length; i++) { output[i] = (OUT) Array.get(in, this.order[i]); } return output; } FieldsFromArray(Class<OUT> clazz, int... indexes); @SuppressWarnings("unchecked") @Override OUT[] extract(Object in);  }
@Test public void testStringArray() { for (int i = 0; i < testStringArray.length; i++) { String[] tmp = { testStringArray[i] }; arrayEqualityCheck(tmp, new FieldsFromArray<String>(String.class, i).extract(testStringArray)); } String[] reverseOrder = new String[testStringArray.length]; for (int i = 0; i < testStringArray.length; i++) { reverseOrder[i] = testStringArray[testStringArray.length - i - 1]; } arrayEqualityCheck(reverseOrder, new FieldsFromArray<String>(String.class, 4, 3, 2, 1, 0).extract(testStringArray)); String[] crazyOrder = { testStringArray[4], testStringArray[1], testStringArray[2] }; arrayEqualityCheck(crazyOrder, new FieldsFromArray<String>(String.class, 4, 1, 2).extract(testStringArray)); }
@Test public void testIntegerArray() { for (int i = 0; i < testIntegerArray.length; i++) { Integer[] tmp = { testIntegerArray[i] }; arrayEqualityCheck(tmp, new FieldsFromArray<Integer>(Integer.class, i).extract(testIntegerArray)); } Integer[] reverseOrder = new Integer[testIntegerArray.length]; for (int i = 0; i < testIntegerArray.length; i++) { reverseOrder[i] = testIntegerArray[testIntegerArray.length - i - 1]; } arrayEqualityCheck(reverseOrder, new FieldsFromArray<Integer>(Integer.class, 4, 3, 2, 1, 0) .extract(testIntegerArray)); Integer[] crazyOrder = { testIntegerArray[4], testIntegerArray[1], testIntegerArray[2] }; arrayEqualityCheck(crazyOrder, new FieldsFromArray<Integer>(Integer.class, 4, 1, 2).extract(testIntegerArray)); }
@Test public void testIntArray() { for (int i = 0; i < testIntArray.length; i++) { Integer[] tmp = { testIntArray[i] }; arrayEqualityCheck(tmp, new FieldsFromArray<Integer>(Integer.class, i).extract(testIntArray)); } Integer[] reverseOrder = new Integer[testIntArray.length]; for (int i = 0; i < testIntArray.length; i++) { reverseOrder[i] = testIntArray[testIntArray.length - i - 1]; } arrayEqualityCheck(reverseOrder, new FieldsFromArray<Integer>(Integer.class, 4, 3, 2, 1, 0).extract(testIntArray)); Integer[] crazyOrder = { testIntArray[4], testIntArray[1], testIntArray[2] }; arrayEqualityCheck(crazyOrder, new FieldsFromArray<Integer>(Integer.class, 4, 1, 2).extract(testIntArray)); }