public static int[] toArray(List<Integer> list) {
        if (list == null) return null;
        int[] array = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);
        }
        return array;
    }
@Test
    public void testToArray() {
        assertArrayEquals(new int[] {3, 2, 1}, Replicas.toArray(Arrays.asList(3, 2, 1)));
        assertArrayEquals(new int[] {}, Replicas.toArray(Collections.emptyList()));
        assertArrayEquals(new int[] {2}, Replicas.toArray(Collections.singletonList(2)));
    }