private RateControlledEntity getNextReadyHighPriorityEntity() { ArrayList<RateControlledEntity> ref = high_priority_entities; int size = ref.size(); int num_checked = 0; while (num_checked < size) { entity_check_count++; next_high_position = next_high_position >= size ? 0 : next_high_position; // make circular RateControlledEntity entity = ref.get(next_high_position); next_high_position++; num_checked++; if (entity.canProcess(read_waiter)) { // is ready return entity; } } return null; // none found ready }