Java 8 migration. Replace statements with lambda
@@ -169,8 +169,7 @@ public class Iterators {
* @since 1.150
*/
public static <T> Iterable<T> reverse(final List<T> lst) {
- return new Iterable<T>() {
- public Iterator<T> iterator() {
+ return () -> {
final ListIterator<T> itr = lst.listIterator(lst.size());
return new Iterator<T>() {
public boolean hasNext() {
@@ -185,7 +184,6 @@ public class Iterators {
itr.remove();
}
};
- }
};
}
@@ -196,8 +194,7 @@ public class Iterators {
* @since 1.492
*/
public static <T> Iterable<T> wrap(final Iterable<T> base) {
- return new Iterable<T>() {
- public Iterator<T> iterator() {
+ return () -> {
final Iterator<T> itr = base.iterator();
return new Iterator<T>() {
public boolean hasNext() {
@@ -212,7 +209,6 @@ public class Iterators {
itr.remove();
}
};
- }
};
}
@@ -320,16 +316,12 @@ public class Iterators {
*/
@SafeVarargs
public static <T> Iterable<T> sequence( final Iterable<? extends T>... iterables ) {
- return new Iterable<T>() {
- public Iterator<T> iterator() {
- return new FlattenIterator<T,Iterable<? extends T>>(ImmutableList.copyOf(iterables)) {
+ return () -> new FlattenIterator<T,Iterable<? extends T>>(ImmutableList.copyOf(iterables)) {
protected Iterator<T> expand(Iterable<? extends T> iterable) {
return Iterators.<T>cast(iterable).iterator();
}
};
}
- };
- }
/**
* Filters another iterator by eliminating duplicates.
@@ -348,11 +340,7 @@ public class Iterators {
* Filters another iterator by eliminating duplicates.
*/
public static <T> Iterable<T> removeDups(final Iterable<T> base) {
- return new Iterable<T>() {
- public Iterator<T> iterator() {
- return removeDups(base.iterator());
- }
- };
+ return () -> removeDups(base.iterator());
}
@SafeVarargs
