@SuppressWarnings("unchecked")
public LimitingResourceQueueElement getFirstElementFrom(LimitingResourceQueue queue, DateAndHour allocationTime) {
final List<LimitingResourceQueueElement> elements = new ArrayList(queue.getLimitingResourceQueueElements());
// First element
final LimitingResourceQueueElement first = elements.get(0);
if (isAfter(first, allocationTime)) {
return first;
}
// Rest of elements
for (int i = 0; i < elements.size(); i++) {
final LimitingResourceQueueElement each = elements.get(i);
if (isInTheMiddle(each, allocationTime) ||
isAfter(each, allocationTime)) {
return each;
}
}