Код: Выделить всё
Foo findFoo(Collection foos, otherarguments)
throws ObjectNotFoundException {
for(Foo foo : foos){
if(/* foo meets some condition*/){
return foo;
}
}
throw new ObjectNotFoundException();
}
Код: Выделить всё
User findUserByName(Collection users, String name)
throws ObjectNotFoundException {
for(User user : users){
if(user.getName().equals(name)){
return user;
}
}
throw new ObjectNotFoundException();
}
Подробнее здесь: https://stackoverflow.com/questions/247 ... -not-found