public static int[] applyOrder(int[] arr, int[] order) {
        if (order.length > arr.length)
            throw new IllegalArgumentException("sort order must not be shorter than array");
        int[] result = new int[order.length];
        for (int i = 0; i < result.length; ++i)
            result[i] = arr[order[i]];
        return result;
    }
@Test
    public void testApplyOrder() {
        assertEquals(from(0, 6, 3, 1, 4), from(ArrayUtil.applyOrder(new int[]{3, 4, 6, 0, 1}, new int[]{3, 2, 0, 4, 1})));
    }