P05 { public static <T> List<T> reverse_customStream(ArrayDeque<T> list) { if (list == null) { throw new IllegalArgumentException("list can't be null"); } return StreamSupport.stream(Spliterators.spliteratorUnknownSize(list.descendingIterator(), Spliterator.ORDERED), false).collect(toList()); }  static List<T> reverse(List<T> list); static List<T> reverse_foreach(List<T> list); static List<T> reverse_IntStream(List<T> list); static List<T> reverse_customStream(ArrayDeque<T> list); static List<T> reverse(LinkedList<T> elements);  }
@Test public void shouldReverseAList_Stream() throws Exception { ArrayDeque<Integer> numbers = arrayDeque(1, 2, 3, 4, 5); assertThat(P05.reverse_customStream(numbers), is(equalTo(Arrays.asList(5, 4, 3, 2, 1)))); }