1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
641 * a small number of additional elements have been traversed.
642 * <p>
643 * For the dropWhile operation if during traversal dropping completes for
644 * some, but not all elements, then it is cancelled globally for the
645 * traversal of all related spliterators (splitting is not cancelled).
646 * Cancellation is governed in the same manner as for the takeWhile
647 * operation.
648 *
649 * @param <T> the type of elements returned by this spliterator
650 * @param <T_SPLITR> the type of the spliterator
651 */
652 abstract static class UnorderedWhileSpliterator<T, T_SPLITR extends Spliterator<T>> implements Spliterator<T> {
653 // Power of two constant minus one used for modulus of count
654 static final int CANCEL_CHECK_COUNT = (1 << 6) - 1;
655
656 // The underlying spliterator
657 final T_SPLITR s;
658 // True if no splitting should be performed, if true then
659 // this spliterator may be used for an underlying spliterator whose
660 // covered elements have an encounter order
661 // See use in stream take/dropWhile default default methods
662 final boolean noSplitting;
663 // True when operations are cancelled for all related spliterators
664 // For taking, spliterators cannot split or traversed
665 // For dropping, spliterators cannot be traversed
666 final AtomicBoolean cancel;
667 // True while taking or dropping should be performed when traversing
668 boolean takeOrDrop = true;
669 // The count of elements traversed
670 int count;
671
672 UnorderedWhileSpliterator(T_SPLITR s, boolean noSplitting) {
673 this.s = s;
674 this.noSplitting = noSplitting;
675 this.cancel = new AtomicBoolean();
676 }
677
678 UnorderedWhileSpliterator(T_SPLITR s, UnorderedWhileSpliterator<T, T_SPLITR> parent) {
679 this.s = s;
680 this.noSplitting = parent.noSplitting;
681 this.cancel = parent.cancel;
|
1 /*
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
641 * a small number of additional elements have been traversed.
642 * <p>
643 * For the dropWhile operation if during traversal dropping completes for
644 * some, but not all elements, then it is cancelled globally for the
645 * traversal of all related spliterators (splitting is not cancelled).
646 * Cancellation is governed in the same manner as for the takeWhile
647 * operation.
648 *
649 * @param <T> the type of elements returned by this spliterator
650 * @param <T_SPLITR> the type of the spliterator
651 */
652 abstract static class UnorderedWhileSpliterator<T, T_SPLITR extends Spliterator<T>> implements Spliterator<T> {
653 // Power of two constant minus one used for modulus of count
654 static final int CANCEL_CHECK_COUNT = (1 << 6) - 1;
655
656 // The underlying spliterator
657 final T_SPLITR s;
658 // True if no splitting should be performed, if true then
659 // this spliterator may be used for an underlying spliterator whose
660 // covered elements have an encounter order
661 // See use in stream take/dropWhile default methods
662 final boolean noSplitting;
663 // True when operations are cancelled for all related spliterators
664 // For taking, spliterators cannot split or traversed
665 // For dropping, spliterators cannot be traversed
666 final AtomicBoolean cancel;
667 // True while taking or dropping should be performed when traversing
668 boolean takeOrDrop = true;
669 // The count of elements traversed
670 int count;
671
672 UnorderedWhileSpliterator(T_SPLITR s, boolean noSplitting) {
673 this.s = s;
674 this.noSplitting = noSplitting;
675 this.cancel = new AtomicBoolean();
676 }
677
678 UnorderedWhileSpliterator(T_SPLITR s, UnorderedWhileSpliterator<T, T_SPLITR> parent) {
679 this.s = s;
680 this.noSplitting = parent.noSplitting;
681 this.cancel = parent.cancel;
|