1 /*
2 * Copyright (c) 2013, 2016, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
35 import java.util.LinkedHashMap;
36 import java.util.LinkedHashSet;
37 import java.util.LinkedList;
38 import java.util.List;
39 import java.util.PriorityQueue;
40 import java.util.Set;
41 import java.util.Spliterator;
42 import java.util.Stack;
43 import java.util.TreeMap;
44 import java.util.TreeSet;
45 import java.util.Vector;
46 import java.util.WeakHashMap;
47 import java.util.function.Function;
48 import java.util.function.Supplier;
49 import java.util.stream.Stream;
50
51 import static org.testng.Assert.assertEquals;
52
53 /**
54 * @test
55 * @bug 8148748 8170155
56 * @summary Spliterator last-binding tests
57 * @run testng SpliteratorLateBindingTest
58 */
59
60 @Test
61 public class SpliteratorLateBindingTest extends SpliteratorLateBindingFailFastHelper {
62
63 static Object[][] spliteratorDataProvider;
64
65 @DataProvider(name = "Source")
66 public static Object[][] sourceDataProvider() {
67 if (spliteratorDataProvider != null) {
68 return spliteratorDataProvider;
69 }
70
71 List<Object[]> data = new ArrayList<>();
72 SpliteratorDataBuilder<Integer> db =
73 new SpliteratorDataBuilder<>(data, 5, Arrays.asList(1, 2, 3, 4));
74
75 // Collections
76
77 db.addList(ArrayList::new);
78
79 db.addList(LinkedList::new);
80
81 db.addList(Vector::new);
82
83 db.addList(AbstractRandomAccessListImpl::new);
84
85 db.addCollection(HashSet::new);
86
87 db.addCollection(LinkedHashSet::new);
88
89 db.addCollection(TreeSet::new);
90
91 db.addCollection(c -> {
92 Stack<Integer> s = new Stack<>();
93 s.addAll(c);
94 return s;
95 });
96
97 db.addCollection(PriorityQueue::new);
98
99 db.addCollection(ArrayDeque::new);
100
101 // Maps
102
103 db.addMap(HashMap::new);
104
105 db.addMap(LinkedHashMap::new);
106
107 db.addMap(IdentityHashMap::new);
108
109 db.addMap(WeakHashMap::new);
110
111 // @@@ Descending maps etc
112 db.addMap(TreeMap::new);
113
114 // BitSet
115
116 List<Integer> bits = List.of(0, 1, 2);
117 Function<BitSet, Spliterator.OfInt> bitsSource = bs -> bs.stream().spliterator();
118 db.add("new BitSet.stream().spliterator() ADD",
119 () -> new IntSource<>(toBitSet(bits), bitsSource, bs -> bs.set(3)));
120 db.add("new BitSet.stream().spliterator() REMOVE",
121 () -> new IntSource<>(toBitSet(bits), bitsSource, bs -> bs.clear(2)));
122
123 // CharSequence
124
125 Function<CharSequence, Spliterator.OfInt> charsSource = sb -> sb.chars().spliterator();
126 Function<CharSequence, Spliterator.OfInt> pointsSource = sb -> sb.codePoints().spliterator();
127
128 db.add("new StringBuilder.chars().spliterator() ADD",
129 () -> new IntSource<>(new StringBuilder("ABC"), charsSource, bs -> bs.append("D"), true));
130 db.add("new StringBuilder.chars().spliterator() REMOVE",
131 () -> new IntSource<>(new StringBuilder("ABC"), charsSource, bs -> bs.deleteCharAt(2), true));
132 db.add("new StringBuilder.codePoints().spliterator() ADD",
133 () -> new IntSource<>(new StringBuilder("ABC"), pointsSource, bs -> bs.append("D"), true));
134 db.add("new StringBuilder.codePoints().spliterator() REMOVE",
135 () -> new IntSource<>(new StringBuilder("ABC"), pointsSource, bs -> bs.deleteCharAt(2), true));
|
1 /*
2 * Copyright (c) 2013, 2024, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
35 import java.util.LinkedHashMap;
36 import java.util.LinkedHashSet;
37 import java.util.LinkedList;
38 import java.util.List;
39 import java.util.PriorityQueue;
40 import java.util.Set;
41 import java.util.Spliterator;
42 import java.util.Stack;
43 import java.util.TreeMap;
44 import java.util.TreeSet;
45 import java.util.Vector;
46 import java.util.WeakHashMap;
47 import java.util.function.Function;
48 import java.util.function.Supplier;
49 import java.util.stream.Stream;
50
51 import static org.testng.Assert.assertEquals;
52
53 /**
54 * @test
55 * @bug 8148748 8170155 8336672
56 * @summary Spliterator last-binding tests
57 * @run testng SpliteratorLateBindingTest
58 */
59
60 @Test
61 public class SpliteratorLateBindingTest extends SpliteratorLateBindingFailFastHelper {
62
63 static Object[][] spliteratorDataProvider;
64
65 @DataProvider(name = "Source")
66 public static Object[][] sourceDataProvider() {
67 if (spliteratorDataProvider != null) {
68 return spliteratorDataProvider;
69 }
70
71 List<Object[]> data = new ArrayList<>();
72 SpliteratorDataBuilder<String> db =
73 new SpliteratorDataBuilder<>(data, "Z", Arrays.asList("A", "B", "C", "D"));
74
75 // Collections
76
77 db.addList(ArrayList::new);
78
79 db.addList(LinkedList::new);
80
81 db.addList(Vector::new);
82
83 db.addList(AbstractRandomAccessListImpl::new);
84
85 db.addCollection(HashSet::new);
86
87 db.addCollection(LinkedHashSet::new);
88
89 db.addCollection(TreeSet::new);
90
91 db.addCollection(c -> {
92 Stack<String> s = new Stack<>();
93 s.addAll(c);
94 return s;
95 });
96
97 db.addCollection(PriorityQueue::new);
98
99 db.addCollection(ArrayDeque::new);
100
101 // Maps
102
103 db.addMap(HashMap::new);
104
105 db.addMap(LinkedHashMap::new);
106
107 db.addMap(IdentityHashMap::new);
108
109 // BUG: Assumes identity
110 db.addMap(WeakHashMap::new);
111
112 // @@@ Descending maps etc
113 db.addMap(TreeMap::new);
114
115 // BitSet
116
117 // BUG: Assumes identity in WeakHashMap
118 List<Integer> bits = List.of(0, 1, 2);
119 Function<BitSet, Spliterator.OfInt> bitsSource = bs -> bs.stream().spliterator();
120 db.add("new BitSet.stream().spliterator() ADD",
121 () -> new IntSource<>(toBitSet(bits), bitsSource, bs -> bs.set(3)));
122 db.add("new BitSet.stream().spliterator() REMOVE",
123 () -> new IntSource<>(toBitSet(bits), bitsSource, bs -> bs.clear(2)));
124
125 // CharSequence
126
127 Function<CharSequence, Spliterator.OfInt> charsSource = sb -> sb.chars().spliterator();
128 Function<CharSequence, Spliterator.OfInt> pointsSource = sb -> sb.codePoints().spliterator();
129
130 db.add("new StringBuilder.chars().spliterator() ADD",
131 () -> new IntSource<>(new StringBuilder("ABC"), charsSource, bs -> bs.append("D"), true));
132 db.add("new StringBuilder.chars().spliterator() REMOVE",
133 () -> new IntSource<>(new StringBuilder("ABC"), charsSource, bs -> bs.deleteCharAt(2), true));
134 db.add("new StringBuilder.codePoints().spliterator() ADD",
135 () -> new IntSource<>(new StringBuilder("ABC"), pointsSource, bs -> bs.append("D"), true));
136 db.add("new StringBuilder.codePoints().spliterator() REMOVE",
137 () -> new IntSource<>(new StringBuilder("ABC"), pointsSource, bs -> bs.deleteCharAt(2), true));
|