-
Notifications
You must be signed in to change notification settings - Fork 171
Open
Milestone
Description
I think I found some inconsistencies in SeqUtils.transform concerning the method characteristics().
We have:
@Override
public int characteristics() {
return delegate.characteristics() & Spliterator.ORDERED;
}
@Override
@SuppressWarnings("unchecked")
public Comparator<? super U> getComparator() {
// This implementation works with the JDK 8, as the information
// is really only used in
// java.util.stream.StreamOpFlag.fromCharacteristics(Spliterator<?> spliterator)
// Currently, the point of this method is only to be used for
// optimisations (e.g. to avoid sorting a stream twice in a row)
return (Comparator) delegate.getComparator();
}But since in calculating the characteristics above we use bitwise AND (&) with Spliterator.ORDERED, ths Spliterator will never report Spliterator.SORTED, and so the method getComparator will never be called in StreamOpFlag.fromCharacteristics:
(characteristics & Spliterator.SORTED) != 0 && spliterator.getComparator() != nullI think characteristics() should return something like this:
public int characteristics() {
return (delegate.characteristics() | Spliterator.ORDERED) & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
}which would mean "we preserve the original characteristics, adding ORDERED if absent, and removing SIZED and SUBSIZED if present".