I was wondering if this approach was correct :
public ITask getState()
{
statePredicate[Some predicate definition];
ITask nextRunnable = null;
try {
nextRunnable = Iterables.find((Iterable)queue, statePredicate);
}
catch (NoSuchElementException e)
{}
return nextRunnable;
}
The points on which I am wondering are :
- should the predicate be cached as a member of the class ?
- I do nothing with the catch, I do not even log it because it is
normal for my app to not find anything. - t return null because I do a final return.
Thank you for your input !
–
1) If the predicate is always the same, I would make it a
static finalclass member.2) There is also a version of
Iterables.findthat you can specify a default value to (assuming you’re using Google Guava). Then you don’t need to deal with theNoSuchElementExceptionat all.3) Is there a reason to cast
queuetoIterable? If this is not necessary, then don’t cast.