blob: 904db7a3db71ae370ecbf44afddaadb93bdc35f7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
/**
* @author jonmv
*/
public class Iterables {
private Iterables() { }
/** Returns a reverse-order iterable view of the given elements. */
public static <T> Iterable<T> reversed(List<T> elements) {
return () -> new Iterator<T>() {
final ListIterator<T> wrapped = elements.listIterator(elements.size());
@Override public boolean hasNext() { return wrapped.hasPrevious(); }
@Override public T next() { return wrapped.previous(); }
@Override public void remove() { wrapped.remove(); }
};
}
}
|