mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-05 16:36:56 +07:00
24 lines
468 B
Java
24 lines
468 B
Java
import java.util.Collection;
|
|
|
|
class X {
|
|
public Foo test(Collection<Foo> collection) {
|
|
Foo result = null;
|
|
int resultWeight = -1;
|
|
for (Foo foo : collection) {
|
|
int fooWeight = foo.getWeight();
|
|
if (result == null || resultWeight <= fooWeight) {
|
|
result = foo;
|
|
resultWeight = fooWeight;
|
|
}
|
|
}
|
|
if (result == null) {
|
|
throw new RuntimeException();
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
interface Foo {
|
|
int getWeight();
|
|
}
|