blob: 4335dc1bdc80dfcab032157a9f4e48deac4eaa92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
package org.zwobble.mammoth.internal.util;
import com.google.common.collect.Iterables;
import java.util.Optional;
import java.util.function.Predicate;
public class MammothIterables {
public static <T> Optional<T> tryGetLast(Iterable<T> iterable) {
return Optional.ofNullable(Iterables.getLast(iterable, null));
}
public static <T> Optional<T> tryFind(Iterable<T> iterable, Predicate<T> predicate) {
for (T element : iterable) {
if (predicate.test(element)) {
return Optional.of(element);
}
}
return Optional.empty();
}
}
|