8306785: fix deficient spliterators for Sequenced Collections

Reviewed-by: psandoz
This commit is contained in:
Stuart Marks 2023-07-12 23:45:42 +00:00
parent 372d0cf752
commit 743e8b8e0a
6 changed files with 26 additions and 12 deletions

View file

@ -948,10 +948,12 @@ public final class Spliterators {
private int index; // current index, modified on advance/split
private final int fence; // one past last index
private final int characteristics;
private long estimatedSize; // estimated size, to help to split evenly
private long estimatedSize; // if >= 0, the estimated size, to help to split evenly
// if -1, exact size is known to be fence - index
/**
* Creates a spliterator covering all of the given array.
* Its size is known exactly and it is SIZED and SUBSIZED.
* @param array the array, assumed to be unmodified during use
* @param additionalCharacteristics Additional spliterator characteristics
* of this spliterator's source or elements beyond {@code SIZED} and
@ -962,7 +964,8 @@ public final class Spliterators {
}
/**
* Creates a spliterator covering the given array and range
* Creates a spliterator covering the given array and range.
* Its size is known exactly and it is SIZED and SUBSIZED.
* @param array the array, assumed to be unmodified during use
* @param origin the least index (inclusive) to cover
* @param fence one past the greatest index to cover
@ -978,6 +981,18 @@ public final class Spliterators {
this.estimatedSize = -1;
}
/**
* Creates a spliterator covering the given array and range but that is
* not SIZED or SUBSIZED. This case occurs as a result of splitting another
* spliterator that is not sized, so it's inappropriate for one of its
* sub-spliterators to be sized.
* @param array the array, assumed to be unmodified during use
* @param origin the least index (inclusive) to cover
* @param fence one past the greatest index to cover
* @param characteristics characteristics of this spliterator's source; {@code SIZED} and
* {@code SUBSIZED} are removed if present
* @param estimatedSize the size estimate; should always be nonnegative
*/
private ArraySpliterator(Object[] array, int origin, int fence, int characteristics, long estimatedSize) {
this.array = array;
this.index = origin;