mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-25 19:21:16 +07:00
26 lines
612 B
Java
26 lines
612 B
Java
// "Replace Stream API chain with loop" "true-preview"
|
|
|
|
import java.util.List;
|
|
import java.util.OptionalInt;
|
|
|
|
public class Main {
|
|
interface Index {
|
|
int asInteger();
|
|
}
|
|
interface IndexSet<S extends Index> {
|
|
List<S> asList();
|
|
}
|
|
|
|
public static OptionalInt min(IndexSet<?> set) {
|
|
boolean seen = false;
|
|
int best = 0;
|
|
for (Index index : set.asList()) {
|
|
int integer = index.asInteger();
|
|
if (!seen || integer < best) {
|
|
seen = true;
|
|
best = integer;
|
|
}
|
|
}
|
|
return seen ? OptionalInt.of(best) : OptionalInt.empty();
|
|
}
|
|
} |