Returns a reversed view of the specified list. For example, Lists.reverse(Arrays.asList(1, 2, 3)) returns a list containing 3, 2, 1. The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of
(List<T> list)
| 851 | |
| 852 | |
| 853 | public static <T> List<T> reverse(List<T> list) { |
| 854 | if (list instanceof ImmutableList) { |
| 855 | return ((ImmutableList<T>) list).reverse(); |
| 856 | } else if (list instanceof ReverseList) { |
| 857 | return ((ReverseList<T>) list).getForwardList(); |
| 858 | } else if (list instanceof RandomAccess) { |
| 859 | return new RandomAccessReverseList<T>(list); |
| 860 | } else { |
| 861 | return new ReverseList<T>(list); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | private static class ReverseList<T> extends AbstractList<T> { |
| 866 | private final List<T> forwardList; |
no test coverage detected