Description
ArrayUtils provides methods to grow arrays, overallocating exponentially, with the possibility of requesting a minimum size.
Sometimes we have an upper limit to the number of elements that would go into that array. In those situations, it would be nice to have a method that grows up to a limit.
For example, DirectoryTaxonomyReader.getBulkOrdinals dynamically grows an array pointing to ordinals missing from the cache (code). But we know ahead of time there can't be more missing ordinals than there are ordinals in the taxonomy. We can limit the array growth to avoid overallocating.
This pattern might be applicable in multiple places. TermsAutomatonScorer seems to use a similar pattern.
The API could look like this:
public static int[] growInRange(int[] array, int minLength, int maxLength)