author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 40788 | 01ffe34b7340 |
child 43522 | f9c6f543c4db |
permissions | -rw-r--r-- |
2 | 1 |
/* |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6207984 6272521 6192552 6269713 6197726 6260652 5073546 4137464 |
|
27 |
* 4155650 4216399 4294891 6282555 6318622 6355327 6383475 6420753 |
|
494
320ce398f07e
6691215: (coll) IdentityHashMap.containsValue(null) returns true when null value not present
martin
parents:
493
diff
changeset
|
28 |
* 6431845 4802633 6570566 6570575 6570631 6570924 6691185 6691215 |
20757
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
29 |
* 4802647 7123424 8024709 |
2 | 30 |
* @summary Run many tests on many Collection and Map implementations |
31 |
* @author Martin Buchholz |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40788
diff
changeset
|
32 |
* @modules java.base/java.util:open |
8536
03570b625eef
7019705: Add -XX:+AggressiveOpts options to MOAT test
mduigou
parents:
7668
diff
changeset
|
33 |
* @run main MOAT |
30046 | 34 |
* @key randomness |
2 | 35 |
*/ |
36 |
||
37 |
/* Mother Of All (Collection) Tests |
|
38 |
* |
|
39 |
* Testing of collection classes is often spotty, because many tests |
|
40 |
* need to be performed on many implementations, but the onus on |
|
41 |
* writing the tests falls on the engineer introducing the new |
|
42 |
* implementation. |
|
43 |
* |
|
44 |
* The idea of this mega-test is that: |
|
45 |
* |
|
46 |
* An engineer adding a new collection implementation could simply add |
|
47 |
* their new implementation to a list of implementations in this |
|
48 |
* test's main method. Any general purpose Collection<Integer> or |
|
49 |
* Map<Integer,Integer> class is appropriate. |
|
50 |
* |
|
51 |
* An engineer fixing a regression could add their regression test here and |
|
52 |
* simultaneously test all other implementations. |
|
53 |
*/ |
|
54 |
||
55 |
import java.io.*; |
|
56 |
import java.util.*; |
|
57 |
import java.util.concurrent.*; |
|
58 |
import static java.util.Collections.*; |
|
23580
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
59 |
import java.lang.reflect.*; |
2 | 60 |
|
61 |
public class MOAT { |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
62 |
// Collections under test must not be initialized to contain this value, |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
63 |
// and maps under test must not contain this value as a key. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
64 |
// It's used as a sentinel for absent-element testing. |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
65 |
static final int ABSENT_VALUE = 778347983; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
66 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
67 |
static final Integer[] integerArray; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
68 |
static { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
69 |
Integer[] ia = new Integer[20]; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
70 |
// fill with 1..20 inclusive |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
71 |
for (int i = 0; i < ia.length; i++) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
72 |
ia[i] = i + 1; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
73 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
74 |
integerArray = ia; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
75 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
76 |
|
2 | 77 |
public static void realMain(String[] args) { |
78 |
||
17441
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
79 |
testCollection(new NewAbstractCollection<Integer>()); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
80 |
testCollection(new NewAbstractSet<Integer>()); |
2 | 81 |
testCollection(new LinkedHashSet<Integer>()); |
82 |
testCollection(new HashSet<Integer>()); |
|
83 |
testCollection(new Vector<Integer>()); |
|
84 |
testCollection(new Vector<Integer>().subList(0,0)); |
|
85 |
testCollection(new ArrayDeque<Integer>()); |
|
86 |
testCollection(new ArrayList<Integer>()); |
|
87 |
testCollection(new ArrayList<Integer>().subList(0,0)); |
|
88 |
testCollection(new LinkedList<Integer>()); |
|
89 |
testCollection(new LinkedList<Integer>().subList(0,0)); |
|
90 |
testCollection(new TreeSet<Integer>()); |
|
18818
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
91 |
testCollection(Collections.checkedList(new ArrayList<Integer>(), Integer.class)); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
92 |
testCollection(Collections.synchronizedList(new ArrayList<Integer>())); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
93 |
testCollection(Collections.checkedSet(new HashSet<Integer>(), Integer.class)); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
94 |
testCollection(Collections.checkedSortedSet(new TreeSet<Integer>(), Integer.class)); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
95 |
testCollection(Collections.checkedNavigableSet(new TreeSet<Integer>(), Integer.class)); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
96 |
testCollection(Collections.synchronizedSet(new HashSet<Integer>())); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
97 |
testCollection(Collections.synchronizedSortedSet(new TreeSet<Integer>())); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
98 |
testCollection(Collections.synchronizedNavigableSet(new TreeSet<Integer>())); |
2 | 99 |
|
100 |
testCollection(new CopyOnWriteArrayList<Integer>()); |
|
101 |
testCollection(new CopyOnWriteArrayList<Integer>().subList(0,0)); |
|
102 |
testCollection(new CopyOnWriteArraySet<Integer>()); |
|
103 |
testCollection(new PriorityQueue<Integer>()); |
|
104 |
testCollection(new PriorityBlockingQueue<Integer>()); |
|
105 |
testCollection(new ArrayBlockingQueue<Integer>(20)); |
|
106 |
testCollection(new LinkedBlockingQueue<Integer>(20)); |
|
107 |
testCollection(new LinkedBlockingDeque<Integer>(20)); |
|
6672 | 108 |
testCollection(new ConcurrentLinkedDeque<Integer>()); |
2 | 109 |
testCollection(new ConcurrentLinkedQueue<Integer>()); |
4110 | 110 |
testCollection(new LinkedTransferQueue<Integer>()); |
2 | 111 |
testCollection(new ConcurrentSkipListSet<Integer>()); |
112 |
testCollection(Arrays.asList(new Integer(42))); |
|
113 |
testCollection(Arrays.asList(1,2,3)); |
|
114 |
testCollection(nCopies(25,1)); |
|
115 |
testImmutableList(nCopies(25,1)); |
|
116 |
||
117 |
testMap(new HashMap<Integer,Integer>()); |
|
118 |
testMap(new LinkedHashMap<Integer,Integer>()); |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
119 |
|
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
120 |
// TODO: Add reliable support for WeakHashMap. |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
121 |
// This test is subject to very rare failures because the GC |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
122 |
// may remove unreferenced-keys from the map at any time. |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
123 |
// testMap(new WeakHashMap<Integer,Integer>()); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
124 |
|
2 | 125 |
testMap(new IdentityHashMap<Integer,Integer>()); |
126 |
testMap(new TreeMap<Integer,Integer>()); |
|
127 |
testMap(new Hashtable<Integer,Integer>()); |
|
128 |
testMap(new ConcurrentHashMap<Integer,Integer>(10, 0.5f)); |
|
129 |
testMap(new ConcurrentSkipListMap<Integer,Integer>()); |
|
18818
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
130 |
testMap(Collections.checkedMap(new HashMap<Integer,Integer>(), Integer.class, Integer.class)); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
131 |
testMap(Collections.checkedSortedMap(new TreeMap<Integer,Integer>(), Integer.class, Integer.class)); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
132 |
testMap(Collections.checkedNavigableMap(new TreeMap<Integer,Integer>(), Integer.class, Integer.class)); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
133 |
testMap(Collections.synchronizedMap(new HashMap<Integer,Integer>())); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
134 |
testMap(Collections.synchronizedSortedMap(new TreeMap<Integer,Integer>())); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
135 |
testMap(Collections.synchronizedNavigableMap(new TreeMap<Integer,Integer>())); |
2 | 136 |
|
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
137 |
// Unmodifiable wrappers |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
138 |
testImmutableSet(unmodifiableSet(new HashSet<>(Arrays.asList(1,2,3)))); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
139 |
testImmutableList(unmodifiableList(Arrays.asList(1,2,3))); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
140 |
testImmutableMap(unmodifiableMap(Collections.singletonMap(1,2))); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
141 |
testCollMutatorsAlwaysThrow(unmodifiableSet(new HashSet<>(Arrays.asList(1,2,3)))); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
142 |
testCollMutatorsAlwaysThrow(unmodifiableSet(Collections.emptySet())); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
143 |
testEmptyCollMutatorsAlwaysThrow(unmodifiableSet(Collections.emptySet())); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
144 |
testListMutatorsAlwaysThrow(unmodifiableList(Arrays.asList(1,2,3))); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
145 |
testListMutatorsAlwaysThrow(unmodifiableList(Collections.emptyList())); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
146 |
testEmptyListMutatorsAlwaysThrow(unmodifiableList(Collections.emptyList())); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
147 |
testMapMutatorsAlwaysThrow(unmodifiableMap(Collections.singletonMap(1,2))); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
148 |
testMapMutatorsAlwaysThrow(unmodifiableMap(Collections.emptyMap())); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
149 |
testEmptyMapMutatorsAlwaysThrow(unmodifiableMap(Collections.emptyMap())); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
150 |
|
2 | 151 |
// Empty collections |
152 |
final List<Integer> emptyArray = Arrays.asList(new Integer[]{}); |
|
153 |
testCollection(emptyArray); |
|
154 |
testEmptyList(emptyArray); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
155 |
THROWS(IndexOutOfBoundsException.class, () -> emptyArray.set(0,1)); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
156 |
THROWS(UnsupportedOperationException.class, () -> emptyArray.add(0,1)); |
2 | 157 |
|
158 |
List<Integer> noOne = nCopies(0,1); |
|
159 |
testCollection(noOne); |
|
160 |
testEmptyList(noOne); |
|
161 |
testImmutableList(noOne); |
|
162 |
||
163 |
Set<Integer> emptySet = emptySet(); |
|
164 |
testCollection(emptySet); |
|
165 |
testEmptySet(emptySet); |
|
166 |
testEmptySet(EMPTY_SET); |
|
18818
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
167 |
testEmptySet(Collections.emptySet()); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
168 |
testEmptySet(Collections.emptySortedSet()); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
169 |
testEmptySet(Collections.emptyNavigableSet()); |
2 | 170 |
testImmutableSet(emptySet); |
171 |
||
172 |
List<Integer> emptyList = emptyList(); |
|
173 |
testCollection(emptyList); |
|
174 |
testEmptyList(emptyList); |
|
175 |
testEmptyList(EMPTY_LIST); |
|
18818
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
176 |
testEmptyList(Collections.emptyList()); |
2 | 177 |
testImmutableList(emptyList); |
178 |
||
179 |
Map<Integer,Integer> emptyMap = emptyMap(); |
|
180 |
testMap(emptyMap); |
|
181 |
testEmptyMap(emptyMap); |
|
182 |
testEmptyMap(EMPTY_MAP); |
|
18818
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
183 |
testEmptyMap(Collections.emptyMap()); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
184 |
testEmptyMap(Collections.emptySortedMap()); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
185 |
testEmptyMap(Collections.emptyNavigableMap()); |
2 | 186 |
testImmutableMap(emptyMap); |
18818
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
187 |
testImmutableMap(Collections.emptyMap()); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
188 |
testImmutableMap(Collections.emptySortedMap()); |
a9ceff754226
7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
mduigou
parents:
17441
diff
changeset
|
189 |
testImmutableMap(Collections.emptyNavigableMap()); |
2 | 190 |
|
191 |
// Singleton collections |
|
192 |
Set<Integer> singletonSet = singleton(1); |
|
193 |
equal(singletonSet.size(), 1); |
|
194 |
testCollection(singletonSet); |
|
195 |
testImmutableSet(singletonSet); |
|
196 |
||
197 |
List<Integer> singletonList = singletonList(1); |
|
198 |
equal(singletonList.size(), 1); |
|
199 |
testCollection(singletonList); |
|
200 |
testImmutableList(singletonList); |
|
201 |
testImmutableList(singletonList.subList(0,1)); |
|
202 |
testImmutableList(singletonList.subList(0,1).subList(0,1)); |
|
203 |
testEmptyList(singletonList.subList(0,0)); |
|
204 |
testEmptyList(singletonList.subList(0,0).subList(0,0)); |
|
205 |
||
206 |
Map<Integer,Integer> singletonMap = singletonMap(1,2); |
|
207 |
equal(singletonMap.size(), 1); |
|
208 |
testMap(singletonMap); |
|
209 |
testImmutableMap(singletonMap); |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
210 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
211 |
// Immutable List |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
212 |
testEmptyList(List.of()); |
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
213 |
testListMutatorsAlwaysThrow(List.of()); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
214 |
testEmptyListMutatorsAlwaysThrow(List.of()); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
215 |
for (List<Integer> list : Arrays.asList( |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
216 |
List.<Integer>of(), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
217 |
List.of(1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
218 |
List.of(1, 2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
219 |
List.of(1, 2, 3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
220 |
List.of(1, 2, 3, 4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
221 |
List.of(1, 2, 3, 4, 5), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
222 |
List.of(1, 2, 3, 4, 5, 6), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
223 |
List.of(1, 2, 3, 4, 5, 6, 7), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
224 |
List.of(1, 2, 3, 4, 5, 6, 7, 8), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
225 |
List.of(1, 2, 3, 4, 5, 6, 7, 8, 9), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
226 |
List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
227 |
List.of(integerArray))) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
228 |
testCollection(list); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
229 |
testImmutableList(list); |
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
230 |
testListMutatorsAlwaysThrow(list); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
231 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
232 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
233 |
// Immutable Set |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
234 |
testEmptySet(Set.of()); |
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
235 |
testCollMutatorsAlwaysThrow(Set.of()); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
236 |
testEmptyCollMutatorsAlwaysThrow(Set.of()); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
237 |
for (Set<Integer> set : Arrays.asList( |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
238 |
Set.<Integer>of(), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
239 |
Set.of(1), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
240 |
Set.of(1, 2), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
241 |
Set.of(1, 2, 3), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
242 |
Set.of(1, 2, 3, 4), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
243 |
Set.of(1, 2, 3, 4, 5), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
244 |
Set.of(1, 2, 3, 4, 5, 6), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
245 |
Set.of(1, 2, 3, 4, 5, 6, 7), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
246 |
Set.of(1, 2, 3, 4, 5, 6, 7, 8), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
247 |
Set.of(1, 2, 3, 4, 5, 6, 7, 8, 9), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
248 |
Set.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
249 |
Set.of(integerArray))) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
250 |
testCollection(set); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
251 |
testImmutableSet(set); |
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
252 |
testCollMutatorsAlwaysThrow(set); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
253 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
254 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
255 |
// Immutable Map |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
256 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
257 |
@SuppressWarnings("unchecked") |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
258 |
Map.Entry<Integer,Integer>[] ea = (Map.Entry<Integer,Integer>[])new Map.Entry<?,?>[20]; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
259 |
for (int i = 0; i < ea.length; i++) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
260 |
ea[i] = Map.entry(i+1, i+101); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
261 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
262 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
263 |
testEmptyMap(Map.of()); |
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
264 |
testMapMutatorsAlwaysThrow(Map.of()); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
265 |
testEmptyMapMutatorsAlwaysThrow(Map.of()); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
266 |
for (Map<Integer,Integer> map : Arrays.asList( |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
267 |
Map.<Integer,Integer>of(), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
268 |
Map.of(1, 101), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
269 |
Map.of(1, 101, 2, 202), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
270 |
Map.of(1, 101, 2, 202, 3, 303), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
271 |
Map.of(1, 101, 2, 202, 3, 303, 4, 404), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
272 |
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
273 |
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505, 6, 606), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
274 |
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505, 6, 606, 7, 707), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
275 |
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505, 6, 606, 7, 707, 8, 808), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
276 |
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505, 6, 606, 7, 707, 8, 808, 9, 909), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
277 |
Map.of(1, 101, 2, 202, 3, 303, 4, 404, 5, 505, 6, 606, 7, 707, 8, 808, 9, 909, 10, 1010), |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
278 |
Map.ofEntries(ea))) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
279 |
testMap(map); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
280 |
testImmutableMap(map); |
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
281 |
testMapMutatorsAlwaysThrow(map); |
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
282 |
} |
2 | 283 |
} |
284 |
||
285 |
private static void checkContainsSelf(Collection<Integer> c) { |
|
286 |
check(c.containsAll(c)); |
|
287 |
check(c.containsAll(Arrays.asList(c.toArray()))); |
|
288 |
check(c.containsAll(Arrays.asList(c.toArray(new Integer[0])))); |
|
289 |
} |
|
290 |
||
291 |
private static void checkContainsEmpty(Collection<Integer> c) { |
|
292 |
check(c.containsAll(new ArrayList<Integer>())); |
|
293 |
} |
|
294 |
||
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
295 |
private static void checkUnique(Set<Integer> s) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
296 |
for (Integer i : s) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
297 |
int count = 0; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
298 |
for (Integer j : s) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
299 |
if (Objects.equals(i,j)) |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
300 |
++count; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
301 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
302 |
check(count == 1); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
303 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
304 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
305 |
|
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
306 |
private static <T> void testEmptyCollection(Collection<T> c) { |
2 | 307 |
check(c.isEmpty()); |
308 |
equal(c.size(), 0); |
|
309 |
equal(c.toString(),"[]"); |
|
310 |
equal(c.toArray().length, 0); |
|
311 |
equal(c.toArray(new Object[0]).length, 0); |
|
3708 | 312 |
check(c.toArray(new Object[]{42})[0] == null); |
2 | 313 |
|
314 |
Object[] a = new Object[1]; a[0] = Boolean.TRUE; |
|
315 |
equal(c.toArray(a), a); |
|
316 |
equal(a[0], null); |
|
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
317 |
testEmptyIterator(c.iterator()); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
318 |
} |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
319 |
|
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
320 |
static <T> void testEmptyIterator(final Iterator<T> it) { |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
321 |
if (rnd.nextBoolean()) |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
322 |
check(! it.hasNext()); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
323 |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
324 |
THROWS(NoSuchElementException.class, () -> it.next()); |
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
325 |
|
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
326 |
try { it.remove(); } |
20476
2d01671506ba
8023339: Refined Collection.removeIf UOE conditions
mduigou
parents:
19855
diff
changeset
|
327 |
catch (IllegalStateException ignored) { pass(); } |
2d01671506ba
8023339: Refined Collection.removeIf UOE conditions
mduigou
parents:
19855
diff
changeset
|
328 |
catch (UnsupportedOperationException ignored) { pass(); } |
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
329 |
catch (Throwable t) { unexpected(t); } |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
330 |
|
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
331 |
if (rnd.nextBoolean()) |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
332 |
check(! it.hasNext()); |
2 | 333 |
} |
334 |
||
335 |
private static void testEmptyList(List<?> c) { |
|
336 |
testEmptyCollection(c); |
|
337 |
equal(c.hashCode(), 1); |
|
338 |
equal2(c, Collections.<Integer>emptyList()); |
|
339 |
} |
|
340 |
||
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
341 |
private static <T> void testEmptySet(Set<T> c) { |
2 | 342 |
testEmptyCollection(c); |
343 |
equal(c.hashCode(), 0); |
|
344 |
equal2(c, Collections.<Integer>emptySet()); |
|
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
345 |
if (c instanceof NavigableSet<?>) |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
346 |
testEmptyIterator(((NavigableSet<T>)c).descendingIterator()); |
2 | 347 |
} |
348 |
||
349 |
private static void testImmutableCollection(final Collection<Integer> c) { |
|
350 |
THROWS(UnsupportedOperationException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
351 |
() -> c.add(99), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
352 |
() -> c.addAll(singleton(99))); |
2 | 353 |
if (! c.isEmpty()) { |
354 |
final Integer first = c.iterator().next(); |
|
355 |
THROWS(UnsupportedOperationException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
356 |
() -> c.clear(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
357 |
() -> c.remove(first), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
358 |
() -> c.removeAll(singleton(first)), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
359 |
() -> c.retainAll(emptyList())); |
2 | 360 |
} |
361 |
} |
|
362 |
||
363 |
private static void testImmutableSet(final Set<Integer> c) { |
|
364 |
testImmutableCollection(c); |
|
365 |
} |
|
366 |
||
367 |
private static void testImmutableList(final List<Integer> c) { |
|
368 |
testList(c); |
|
369 |
testImmutableCollection(c); |
|
370 |
THROWS(UnsupportedOperationException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
371 |
() -> c.set(0,42), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
372 |
() -> c.add(0,42), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
373 |
() -> c.addAll(0,singleton(86))); |
2 | 374 |
if (! c.isEmpty()) |
375 |
THROWS(UnsupportedOperationException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
376 |
() -> { Iterator<Integer> it = c.iterator(); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
377 |
it.next(); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
378 |
it.remove(); }, |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
379 |
() -> { ListIterator<Integer> it = c.listIterator(); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
380 |
it.next(); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
381 |
it.remove(); }); |
2 | 382 |
} |
383 |
||
40788
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
384 |
/** |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
385 |
* Test that calling a mutator always throws UOE, even if the mutator |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
386 |
* wouldn't actually do anything, given its arguments. |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
387 |
* |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
388 |
* @param c the collection instance to test |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
389 |
*/ |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
390 |
private static void testCollMutatorsAlwaysThrow(Collection<Integer> c) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
391 |
THROWS(UnsupportedOperationException.class, |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
392 |
() -> c.addAll(Collections.emptyList()), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
393 |
() -> c.remove(ABSENT_VALUE), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
394 |
() -> c.removeAll(Collections.emptyList()), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
395 |
() -> c.removeIf(x -> false), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
396 |
() -> c.retainAll(c)); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
397 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
398 |
|
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
399 |
/** |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
400 |
* Test that calling a mutator always throws UOE, even if the mutator |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
401 |
* wouldn't actually do anything on an empty collection. |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
402 |
* |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
403 |
* @param c the collection instance to test, must be empty |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
404 |
*/ |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
405 |
private static void testEmptyCollMutatorsAlwaysThrow(Collection<Integer> c) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
406 |
if (! c.isEmpty()) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
407 |
fail("collection is not empty"); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
408 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
409 |
THROWS(UnsupportedOperationException.class, |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
410 |
() -> c.clear()); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
411 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
412 |
|
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
413 |
/** |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
414 |
* As above, for a list. |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
415 |
* |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
416 |
* @param c the list instance to test |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
417 |
*/ |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
418 |
private static void testListMutatorsAlwaysThrow(List<Integer> c) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
419 |
testCollMutatorsAlwaysThrow(c); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
420 |
THROWS(UnsupportedOperationException.class, |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
421 |
() -> c.addAll(0, Collections.emptyList())); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
422 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
423 |
|
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
424 |
/** |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
425 |
* As above, for an empty list. |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
426 |
* |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
427 |
* @param c the list instance to test, must be empty |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
428 |
*/ |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
429 |
private static void testEmptyListMutatorsAlwaysThrow(List<Integer> c) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
430 |
if (! c.isEmpty()) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
431 |
fail("list is not empty"); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
432 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
433 |
testEmptyCollMutatorsAlwaysThrow(c); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
434 |
THROWS(UnsupportedOperationException.class, |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
435 |
() -> c.replaceAll(x -> x), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
436 |
() -> c.sort(null)); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
437 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
438 |
|
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
439 |
/** |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
440 |
* As above, for a map. |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
441 |
* |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
442 |
* @param m the map instance to test |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
443 |
*/ |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
444 |
private static void testMapMutatorsAlwaysThrow(Map<Integer,Integer> m) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
445 |
THROWS(UnsupportedOperationException.class, |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
446 |
() -> m.compute(ABSENT_VALUE, (k, v) -> null), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
447 |
() -> m.computeIfAbsent(ABSENT_VALUE, k -> null), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
448 |
() -> m.computeIfPresent(ABSENT_VALUE, (k, v) -> null), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
449 |
() -> m.merge(ABSENT_VALUE, 0, (k, v) -> null), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
450 |
() -> m.putAll(Collections.emptyMap()), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
451 |
() -> m.remove(ABSENT_VALUE), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
452 |
() -> m.remove(ABSENT_VALUE, 0), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
453 |
() -> m.replace(ABSENT_VALUE, 0), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
454 |
() -> m.replace(ABSENT_VALUE, 0, 1)); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
455 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
456 |
|
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
457 |
/** |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
458 |
* As above, for an empty map. |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
459 |
* |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
460 |
* @param map the map instance to test, must be empty |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
461 |
*/ |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
462 |
private static void testEmptyMapMutatorsAlwaysThrow(Map<Integer,Integer> m) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
463 |
if (! m.isEmpty()) { |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
464 |
fail("map is not empty"); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
465 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
466 |
THROWS(UnsupportedOperationException.class, |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
467 |
() -> m.clear(), |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
468 |
() -> m.replaceAll((k, v) -> v)); |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
469 |
} |
01ffe34b7340
8159404: throw UnsupportedOperationException unconditionally for mutator methods
smarks
parents:
34527
diff
changeset
|
470 |
|
2 | 471 |
private static void clear(Collection<Integer> c) { |
472 |
try { c.clear(); } |
|
473 |
catch (Throwable t) { unexpected(t); } |
|
474 |
testEmptyCollection(c); |
|
475 |
} |
|
476 |
||
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
477 |
private static <K,V> void testEmptyMap(final Map<K,V> m) { |
2 | 478 |
check(m.isEmpty()); |
479 |
equal(m.size(), 0); |
|
480 |
equal(m.toString(),"{}"); |
|
481 |
testEmptySet(m.keySet()); |
|
482 |
testEmptySet(m.entrySet()); |
|
483 |
testEmptyCollection(m.values()); |
|
494
320ce398f07e
6691215: (coll) IdentityHashMap.containsValue(null) returns true when null value not present
martin
parents:
493
diff
changeset
|
484 |
|
320ce398f07e
6691215: (coll) IdentityHashMap.containsValue(null) returns true when null value not present
martin
parents:
493
diff
changeset
|
485 |
try { check(! m.containsValue(null)); } |
20476
2d01671506ba
8023339: Refined Collection.removeIf UOE conditions
mduigou
parents:
19855
diff
changeset
|
486 |
catch (NullPointerException ignored) { /* OK */ } |
494
320ce398f07e
6691215: (coll) IdentityHashMap.containsValue(null) returns true when null value not present
martin
parents:
493
diff
changeset
|
487 |
try { check(! m.containsKey(null)); } |
20476
2d01671506ba
8023339: Refined Collection.removeIf UOE conditions
mduigou
parents:
19855
diff
changeset
|
488 |
catch (NullPointerException ignored) { /* OK */ } |
494
320ce398f07e
6691215: (coll) IdentityHashMap.containsValue(null) returns true when null value not present
martin
parents:
493
diff
changeset
|
489 |
check(! m.containsValue(1)); |
320ce398f07e
6691215: (coll) IdentityHashMap.containsValue(null) returns true when null value not present
martin
parents:
493
diff
changeset
|
490 |
check(! m.containsKey(1)); |
2 | 491 |
} |
492 |
||
493 |
private static void testImmutableMap(final Map<Integer,Integer> m) { |
|
494 |
THROWS(UnsupportedOperationException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
495 |
() -> m.put(1,1), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
496 |
() -> m.putAll(singletonMap(1,1))); |
2 | 497 |
if (! m.isEmpty()) { |
498 |
final Integer first = m.keySet().iterator().next(); |
|
499 |
THROWS(UnsupportedOperationException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
500 |
() -> m.remove(first), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
501 |
() -> m.clear()); |
2 | 502 |
final Map.Entry<Integer,Integer> me |
503 |
= m.entrySet().iterator().next(); |
|
504 |
Integer key = me.getKey(); |
|
505 |
Integer val = me.getValue(); |
|
506 |
THROWS(UnsupportedOperationException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
507 |
() -> me.setValue(3)); |
2 | 508 |
equal(key, me.getKey()); |
509 |
equal(val, me.getValue()); |
|
510 |
} |
|
511 |
testImmutableSet(m.keySet()); |
|
512 |
testImmutableCollection(m.values()); |
|
513 |
//testImmutableSet(m.entrySet()); |
|
514 |
} |
|
515 |
||
516 |
private static void clear(Map<?,?> m) { |
|
517 |
try { m.clear(); } |
|
518 |
catch (Throwable t) { unexpected(t); } |
|
519 |
testEmptyMap(m); |
|
520 |
} |
|
521 |
||
522 |
private static void oneElement(Collection<Integer> c) { |
|
523 |
clear(c); |
|
524 |
try { |
|
525 |
check(c.add(-42)); |
|
526 |
equal(c.toString(), "[-42]"); |
|
527 |
if (c instanceof Set) check(! c.add(-42)); |
|
528 |
} catch (Throwable t) { unexpected(t); } |
|
529 |
check(! c.isEmpty()); check(c.size() == 1); |
|
530 |
} |
|
531 |
||
532 |
private static boolean supportsAdd(Collection<Integer> c) { |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
533 |
try { check(c.add(ABSENT_VALUE)); } |
2 | 534 |
catch (UnsupportedOperationException t) { return false; } |
535 |
catch (Throwable t) { unexpected(t); } |
|
536 |
||
537 |
try { |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
538 |
check(c.contains(ABSENT_VALUE)); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
539 |
check(c.remove(ABSENT_VALUE)); |
2 | 540 |
} catch (Throwable t) { unexpected(t); } |
541 |
return true; |
|
542 |
} |
|
543 |
||
544 |
private static boolean supportsRemove(Collection<Integer> c) { |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
545 |
try { check(! c.remove(ABSENT_VALUE)); } |
2 | 546 |
catch (UnsupportedOperationException t) { return false; } |
547 |
catch (Throwable t) { unexpected(t); } |
|
548 |
return true; |
|
549 |
} |
|
550 |
||
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
551 |
// 6260652: (coll) Arrays.asList(x).toArray().getClass() |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
552 |
// should be Object[].class |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
553 |
// Fixed in jdk9, but not jdk8 ... |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
554 |
static final boolean needToWorkAround6260652 = |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
555 |
Arrays.asList("").toArray().getClass() != Object[].class; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
556 |
|
2 | 557 |
private static void checkFunctionalInvariants(Collection<Integer> c) { |
558 |
try { |
|
559 |
checkContainsSelf(c); |
|
560 |
checkContainsEmpty(c); |
|
561 |
check(c.size() != 0 ^ c.isEmpty()); |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
562 |
check(! c.contains(ABSENT_VALUE)); |
2 | 563 |
|
564 |
{ |
|
565 |
int size = 0; |
|
566 |
for (Integer i : c) size++; |
|
567 |
check(c.size() == size); |
|
568 |
} |
|
569 |
||
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
570 |
if (c instanceof Set) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
571 |
checkUnique((Set<Integer>)c); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
572 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
573 |
|
2 | 574 |
check(c.toArray().length == c.size()); |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
575 |
check(c.toArray().getClass() == Object[].class |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
576 |
|| |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
577 |
(needToWorkAround6260652 && |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
578 |
c.getClass().getName().equals("java.util.Arrays$ArrayList"))); |
2 | 579 |
for (int size : new int[]{0,1,c.size(), c.size()+1}) { |
580 |
Integer[] a = c.toArray(new Integer[size]); |
|
581 |
check((size > c.size()) || a.length == c.size()); |
|
582 |
int i = 0; for (Integer j : c) check(a[i++] == j); |
|
583 |
check((size <= c.size()) || (a[c.size()] == null)); |
|
584 |
check(a.getClass() == Integer[].class); |
|
585 |
} |
|
586 |
||
587 |
check(c.equals(c)); |
|
588 |
if (c instanceof Serializable) { |
|
589 |
//System.out.printf("Serializing %s%n", c.getClass().getName()); |
|
590 |
try { |
|
591 |
Object clone = serialClone(c); |
|
592 |
equal(c instanceof Serializable, |
|
593 |
clone instanceof Serializable); |
|
594 |
equal(c instanceof RandomAccess, |
|
595 |
clone instanceof RandomAccess); |
|
596 |
if ((c instanceof List) || (c instanceof Set)) |
|
597 |
equal(c, clone); |
|
598 |
else |
|
599 |
equal(new HashSet<Integer>(c), |
|
600 |
new HashSet<Integer>(serialClone(c))); |
|
601 |
} catch (Error xxx) { |
|
602 |
if (! (xxx.getCause() instanceof NotSerializableException)) |
|
603 |
throw xxx; |
|
604 |
} |
|
605 |
} |
|
606 |
} |
|
607 |
catch (Throwable t) { unexpected(t); } |
|
608 |
} |
|
609 |
||
610 |
//---------------------------------------------------------------- |
|
611 |
// If add(null) succeeds, contains(null) & remove(null) should succeed |
|
612 |
//---------------------------------------------------------------- |
|
613 |
private static void testNullElement(Collection<Integer> c) { |
|
614 |
||
615 |
try { |
|
616 |
check(c.add(null)); |
|
617 |
if (c.size() == 1) |
|
618 |
equal(c.toString(), "[null]"); |
|
619 |
try { |
|
620 |
checkFunctionalInvariants(c); |
|
621 |
check(c.contains(null)); |
|
622 |
check(c.remove(null)); |
|
623 |
} |
|
624 |
catch (Throwable t) { unexpected(t); } |
|
625 |
} |
|
626 |
catch (NullPointerException e) { /* OK */ } |
|
627 |
catch (Throwable t) { unexpected(t); } |
|
628 |
} |
|
629 |
||
630 |
//---------------------------------------------------------------- |
|
631 |
// If add("x") succeeds, contains("x") & remove("x") should succeed |
|
632 |
//---------------------------------------------------------------- |
|
633 |
@SuppressWarnings("unchecked") |
|
634 |
private static void testStringElement(Collection<Integer> c) { |
|
635 |
Collection x = (Collection)c; // Make type-unsafe |
|
636 |
try { |
|
637 |
check(x.add("x")); |
|
638 |
try { |
|
639 |
check(x.contains("x")); |
|
640 |
check(x.remove("x")); |
|
641 |
} catch (Throwable t) { unexpected(t); } |
|
642 |
} |
|
643 |
catch (ClassCastException e) { /* OK */ } |
|
644 |
catch (Throwable t) { unexpected(t); } |
|
645 |
} |
|
646 |
||
647 |
private static void testConcurrentCollection(Collection<Integer> c) { |
|
648 |
try { |
|
649 |
c.add(1); |
|
650 |
Iterator<Integer> it = c.iterator(); |
|
651 |
check(it.hasNext()); |
|
652 |
clear(c); |
|
653 |
check(it.next() instanceof Integer); // No CME |
|
654 |
check(c.isEmpty()); |
|
655 |
} |
|
656 |
catch (Throwable t) { unexpected(t); } |
|
657 |
} |
|
658 |
||
659 |
private static void testQueue(Queue<Integer> q) { |
|
660 |
q.clear(); |
|
4184 | 661 |
for (int i = 0; i < 5; i++) { |
662 |
testQueueAddRemove(q, null); |
|
663 |
testQueueAddRemove(q, 537); |
|
2 | 664 |
q.add(i); |
4184 | 665 |
} |
2 | 666 |
equal(q.size(), 5); |
667 |
checkFunctionalInvariants(q); |
|
668 |
q.poll(); |
|
669 |
equal(q.size(), 4); |
|
670 |
checkFunctionalInvariants(q); |
|
6672 | 671 |
if ((q instanceof LinkedBlockingQueue) || |
672 |
(q instanceof LinkedBlockingDeque) || |
|
673 |
(q instanceof ConcurrentLinkedDeque) || |
|
3415
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
674 |
(q instanceof ConcurrentLinkedQueue)) { |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
675 |
testQueueIteratorRemove(q); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
676 |
} |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
677 |
} |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
678 |
|
4184 | 679 |
private static void testQueueAddRemove(final Queue<Integer> q, |
680 |
final Integer e) { |
|
681 |
final List<Integer> originalContents = new ArrayList<Integer>(q); |
|
682 |
final boolean isEmpty = q.isEmpty(); |
|
683 |
final boolean isList = (q instanceof List); |
|
684 |
final List asList = isList ? (List) q : null; |
|
685 |
check(!q.contains(e)); |
|
686 |
try { |
|
687 |
q.add(e); |
|
688 |
} catch (NullPointerException npe) { |
|
689 |
check(e == null); |
|
690 |
return; // Null elements not supported |
|
691 |
} |
|
692 |
check(q.contains(e)); |
|
693 |
check(q.remove(e)); |
|
694 |
check(!q.contains(e)); |
|
695 |
equal(new ArrayList<Integer>(q), originalContents); |
|
696 |
||
697 |
if (q instanceof Deque<?>) { |
|
698 |
final Deque<Integer> deq = (Deque<Integer>) q; |
|
699 |
final List<Integer> singleton = Collections.singletonList(e); |
|
700 |
||
701 |
// insert, query, remove element at head |
|
702 |
if (isEmpty) { |
|
703 |
THROWS(NoSuchElementException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
704 |
() -> deq.getFirst(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
705 |
() -> deq.element(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
706 |
() -> deq.iterator().next()); |
4184 | 707 |
check(deq.peekFirst() == null); |
708 |
check(deq.peek() == null); |
|
709 |
} else { |
|
710 |
check(deq.getFirst() != e); |
|
711 |
check(deq.element() != e); |
|
712 |
check(deq.iterator().next() != e); |
|
713 |
check(deq.peekFirst() != e); |
|
714 |
check(deq.peek() != e); |
|
715 |
} |
|
716 |
check(!deq.contains(e)); |
|
717 |
check(!deq.removeFirstOccurrence(e)); |
|
718 |
check(!deq.removeLastOccurrence(e)); |
|
719 |
if (isList) { |
|
720 |
check(asList.indexOf(e) == -1); |
|
721 |
check(asList.lastIndexOf(e) == -1); |
|
722 |
} |
|
723 |
switch (rnd.nextInt(isList ? 4 : 3)) { |
|
724 |
case 0: deq.addFirst(e); break; |
|
725 |
case 1: check(deq.offerFirst(e)); break; |
|
726 |
case 2: deq.push(e); break; |
|
727 |
case 3: asList.add(0, e); break; |
|
728 |
default: throw new AssertionError(); |
|
729 |
} |
|
730 |
check(deq.peekFirst() == e); |
|
731 |
check(deq.getFirst() == e); |
|
732 |
check(deq.element() == e); |
|
733 |
check(deq.peek() == e); |
|
734 |
check(deq.iterator().next() == e); |
|
735 |
check(deq.contains(e)); |
|
736 |
if (isList) { |
|
737 |
check(asList.get(0) == e); |
|
738 |
check(asList.indexOf(e) == 0); |
|
739 |
check(asList.lastIndexOf(e) == 0); |
|
740 |
check(asList.subList(0, 1).equals(singleton)); |
|
741 |
} |
|
742 |
switch (rnd.nextInt(isList ? 11 : 9)) { |
|
743 |
case 0: check(deq.pollFirst() == e); break; |
|
744 |
case 1: check(deq.removeFirst() == e); break; |
|
745 |
case 2: check(deq.remove() == e); break; |
|
746 |
case 3: check(deq.pop() == e); break; |
|
747 |
case 4: check(deq.removeFirstOccurrence(e)); break; |
|
748 |
case 5: check(deq.removeLastOccurrence(e)); break; |
|
749 |
case 6: check(deq.remove(e)); break; |
|
750 |
case 7: check(deq.removeAll(singleton)); break; |
|
751 |
case 8: Iterator it = deq.iterator(); it.next(); it.remove(); break; |
|
752 |
case 9: asList.remove(0); break; |
|
753 |
case 10: asList.subList(0, 1).clear(); break; |
|
754 |
default: throw new AssertionError(); |
|
755 |
} |
|
756 |
if (isEmpty) { |
|
757 |
THROWS(NoSuchElementException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
758 |
() -> deq.getFirst(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
759 |
() -> deq.element(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
760 |
() -> deq.iterator().next()); |
4184 | 761 |
check(deq.peekFirst() == null); |
762 |
check(deq.peek() == null); |
|
763 |
} else { |
|
764 |
check(deq.getFirst() != e); |
|
765 |
check(deq.element() != e); |
|
766 |
check(deq.iterator().next() != e); |
|
767 |
check(deq.peekFirst() != e); |
|
768 |
check(deq.peek() != e); |
|
769 |
} |
|
770 |
check(!deq.contains(e)); |
|
771 |
check(!deq.removeFirstOccurrence(e)); |
|
772 |
check(!deq.removeLastOccurrence(e)); |
|
773 |
if (isList) { |
|
774 |
check(isEmpty || asList.get(0) != e); |
|
775 |
check(asList.indexOf(e) == -1); |
|
776 |
check(asList.lastIndexOf(e) == -1); |
|
777 |
} |
|
778 |
equal(new ArrayList<Integer>(deq), originalContents); |
|
779 |
||
780 |
// insert, query, remove element at tail |
|
781 |
if (isEmpty) { |
|
782 |
check(deq.peekLast() == null); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
783 |
THROWS(NoSuchElementException.class, () -> deq.getLast()); |
4184 | 784 |
} else { |
785 |
check(deq.peekLast() != e); |
|
786 |
check(deq.getLast() != e); |
|
787 |
} |
|
788 |
switch (rnd.nextInt(isList ? 6 : 4)) { |
|
789 |
case 0: deq.addLast(e); break; |
|
790 |
case 1: check(deq.offerLast(e)); break; |
|
791 |
case 2: check(deq.add(e)); break; |
|
792 |
case 3: deq.addAll(singleton); break; |
|
793 |
case 4: asList.addAll(deq.size(), singleton); break; |
|
794 |
case 5: asList.add(deq.size(), e); break; |
|
795 |
default: throw new AssertionError(); |
|
796 |
} |
|
797 |
check(deq.peekLast() == e); |
|
798 |
check(deq.getLast() == e); |
|
799 |
check(deq.contains(e)); |
|
800 |
if (isList) { |
|
801 |
ListIterator it = asList.listIterator(asList.size()); |
|
802 |
check(it.previous() == e); |
|
803 |
check(asList.get(asList.size() - 1) == e); |
|
804 |
check(asList.indexOf(e) == asList.size() - 1); |
|
805 |
check(asList.lastIndexOf(e) == asList.size() - 1); |
|
806 |
int size = asList.size(); |
|
807 |
check(asList.subList(size - 1, size).equals(singleton)); |
|
808 |
} |
|
809 |
switch (rnd.nextInt(isList ? 8 : 6)) { |
|
810 |
case 0: check(deq.pollLast() == e); break; |
|
811 |
case 1: check(deq.removeLast() == e); break; |
|
812 |
case 2: check(deq.removeFirstOccurrence(e)); break; |
|
813 |
case 3: check(deq.removeLastOccurrence(e)); break; |
|
814 |
case 4: check(deq.remove(e)); break; |
|
815 |
case 5: check(deq.removeAll(singleton)); break; |
|
816 |
case 6: asList.remove(asList.size() - 1); break; |
|
817 |
case 7: |
|
818 |
ListIterator it = asList.listIterator(asList.size()); |
|
819 |
it.previous(); |
|
820 |
it.remove(); |
|
821 |
break; |
|
822 |
default: throw new AssertionError(); |
|
823 |
} |
|
824 |
if (isEmpty) { |
|
825 |
check(deq.peekLast() == null); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
826 |
THROWS(NoSuchElementException.class, () -> deq.getLast()); |
4184 | 827 |
} else { |
828 |
check(deq.peekLast() != e); |
|
829 |
check(deq.getLast() != e); |
|
830 |
} |
|
831 |
check(!deq.contains(e)); |
|
832 |
equal(new ArrayList<Integer>(deq), originalContents); |
|
833 |
||
834 |
// Test operations on empty deque |
|
835 |
switch (rnd.nextInt(isList ? 4 : 2)) { |
|
836 |
case 0: deq.clear(); break; |
|
837 |
case 1: |
|
838 |
Iterator it = deq.iterator(); |
|
839 |
while (it.hasNext()) { |
|
840 |
it.next(); |
|
841 |
it.remove(); |
|
842 |
} |
|
843 |
break; |
|
844 |
case 2: asList.subList(0, asList.size()).clear(); break; |
|
845 |
case 3: |
|
846 |
ListIterator lit = asList.listIterator(asList.size()); |
|
847 |
while (lit.hasPrevious()) { |
|
848 |
lit.previous(); |
|
849 |
lit.remove(); |
|
850 |
} |
|
851 |
break; |
|
852 |
default: throw new AssertionError(); |
|
853 |
} |
|
854 |
testEmptyCollection(deq); |
|
855 |
check(!deq.iterator().hasNext()); |
|
856 |
if (isList) { |
|
857 |
check(!asList.listIterator().hasPrevious()); |
|
858 |
THROWS(NoSuchElementException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
859 |
() -> asList.listIterator().previous()); |
4184 | 860 |
} |
861 |
THROWS(NoSuchElementException.class, |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
862 |
() -> deq.iterator().next(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
863 |
() -> deq.element(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
864 |
() -> deq.getFirst(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
865 |
() -> deq.getLast(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
866 |
() -> deq.pop(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
867 |
() -> deq.remove(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
868 |
() -> deq.removeFirst(), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
869 |
() -> deq.removeLast()); |
4184 | 870 |
|
871 |
check(deq.poll() == null); |
|
872 |
check(deq.pollFirst() == null); |
|
873 |
check(deq.pollLast() == null); |
|
874 |
check(deq.peek() == null); |
|
875 |
check(deq.peekFirst() == null); |
|
876 |
check(deq.peekLast() == null); |
|
877 |
check(!deq.removeFirstOccurrence(e)); |
|
878 |
check(!deq.removeLastOccurrence(e)); |
|
879 |
||
880 |
check(deq.addAll(originalContents) == !isEmpty); |
|
881 |
equal(new ArrayList<Integer>(deq), originalContents); |
|
882 |
check(!deq.addAll(Collections.<Integer>emptyList())); |
|
883 |
equal(new ArrayList<Integer>(deq), originalContents); |
|
884 |
} |
|
885 |
} |
|
886 |
||
3415
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
887 |
private static void testQueueIteratorRemove(Queue<Integer> q) { |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
888 |
System.err.printf("testQueueIteratorRemove %s%n", |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
889 |
q.getClass().getSimpleName()); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
890 |
q.clear(); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
891 |
for (int i = 0; i < 5; i++) |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
892 |
q.add(i); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
893 |
Iterator<Integer> it = q.iterator(); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
894 |
check(it.hasNext()); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
895 |
for (int i = 3; i >= 0; i--) |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
896 |
q.remove(i); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
897 |
equal(it.next(), 0); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
898 |
equal(it.next(), 4); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
899 |
|
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
900 |
q.clear(); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
901 |
for (int i = 0; i < 5; i++) |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
902 |
q.add(i); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
903 |
it = q.iterator(); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
904 |
equal(it.next(), 0); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
905 |
check(it.hasNext()); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
906 |
for (int i = 1; i < 4; i++) |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
907 |
q.remove(i); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
908 |
equal(it.next(), 1); |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
909 |
equal(it.next(), 4); |
2 | 910 |
} |
911 |
||
912 |
private static void testList(final List<Integer> l) { |
|
913 |
//---------------------------------------------------------------- |
|
914 |
// 4802633: (coll) AbstractList.addAll(-1,emptyCollection) |
|
915 |
// doesn't throw IndexOutOfBoundsException |
|
916 |
//---------------------------------------------------------------- |
|
917 |
try { |
|
918 |
l.addAll(-1, Collections.<Integer>emptyList()); |
|
919 |
fail("Expected IndexOutOfBoundsException not thrown"); |
|
920 |
} |
|
20476
2d01671506ba
8023339: Refined Collection.removeIf UOE conditions
mduigou
parents:
19855
diff
changeset
|
921 |
catch (UnsupportedOperationException ignored) {/* OK */} |
2d01671506ba
8023339: Refined Collection.removeIf UOE conditions
mduigou
parents:
19855
diff
changeset
|
922 |
catch (IndexOutOfBoundsException ignored) {/* OK */} |
2 | 923 |
catch (Throwable t) { unexpected(t); } |
924 |
||
925 |
// equal(l instanceof Serializable, |
|
926 |
// l.subList(0,0) instanceof Serializable); |
|
927 |
if (l.subList(0,0) instanceof Serializable) |
|
928 |
check(l instanceof Serializable); |
|
929 |
||
930 |
equal(l instanceof RandomAccess, |
|
931 |
l.subList(0,0) instanceof RandomAccess); |
|
23580
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
932 |
|
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
933 |
l.iterator(); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
934 |
l.listIterator(); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
935 |
l.listIterator(0); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
936 |
l.listIterator(l.size()); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
937 |
THROWS(IndexOutOfBoundsException.class, |
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
938 |
() -> l.listIterator(-1), |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
939 |
() -> l.listIterator(l.size() + 1)); |
23580
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
940 |
|
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
941 |
if (l instanceof AbstractList) { |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
942 |
try { |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
943 |
int size = l.size(); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
944 |
AbstractList<Integer> abList = (AbstractList<Integer>) l; |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
945 |
Method m = AbstractList.class.getDeclaredMethod("removeRange", new Class[] { int.class, int.class }); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
946 |
m.setAccessible(true); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
947 |
m.invoke(abList, new Object[] { 0, 0 }); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
948 |
m.invoke(abList, new Object[] { size, size }); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
949 |
equal(size, l.size()); |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
950 |
} |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
951 |
catch (UnsupportedOperationException ignored) {/* OK */} |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
952 |
catch (Throwable t) { unexpected(t); } |
1055a611c69b
8014066: Remove redundant restriction from ArrayList#removeRange() spec
igerasim
parents:
23010
diff
changeset
|
953 |
} |
2 | 954 |
} |
955 |
||
956 |
private static void testCollection(Collection<Integer> c) { |
|
3415
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
957 |
try { testCollection1(c); } |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
958 |
catch (Throwable t) { unexpected(t); } |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
959 |
} |
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
960 |
|
79309d6eab38
6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
dl
parents:
2428
diff
changeset
|
961 |
private static void testCollection1(Collection<Integer> c) { |
2 | 962 |
|
963 |
System.out.println("\n==> " + c.getClass().getName()); |
|
964 |
||
965 |
checkFunctionalInvariants(c); |
|
966 |
||
967 |
if (! supportsAdd(c)) return; |
|
968 |
//System.out.println("add() supported"); |
|
969 |
||
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
970 |
if (c instanceof NavigableSet) { |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
971 |
System.out.println("NavigableSet tests..."); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
972 |
|
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
973 |
NavigableSet<Integer> ns = (NavigableSet<Integer>)c; |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
974 |
testNavigableSet(ns); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
975 |
testNavigableSet(ns.headSet(6, false)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
976 |
testNavigableSet(ns.headSet(5, true)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
977 |
testNavigableSet(ns.tailSet(0, false)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
978 |
testNavigableSet(ns.tailSet(1, true)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
979 |
testNavigableSet(ns.subSet(0, false, 5, true)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
980 |
testNavigableSet(ns.subSet(1, true, 6, false)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
981 |
} |
2 | 982 |
|
983 |
if (c instanceof Queue) |
|
984 |
testQueue((Queue<Integer>)c); |
|
985 |
||
986 |
if (c instanceof List) |
|
987 |
testList((List<Integer>)c); |
|
988 |
||
989 |
check(supportsRemove(c)); |
|
990 |
||
991 |
try { |
|
992 |
oneElement(c); |
|
993 |
checkFunctionalInvariants(c); |
|
994 |
} |
|
995 |
catch (Throwable t) { unexpected(t); } |
|
996 |
||
997 |
clear(c); testNullElement(c); |
|
998 |
oneElement(c); testNullElement(c); |
|
999 |
||
1000 |
clear(c); testStringElement(c); |
|
1001 |
oneElement(c); testStringElement(c); |
|
1002 |
||
1003 |
if (c.getClass().getName().matches(".*concurrent.*")) |
|
1004 |
testConcurrentCollection(c); |
|
1005 |
||
1006 |
//---------------------------------------------------------------- |
|
1007 |
// The "all" operations should throw NPE when passed null |
|
1008 |
//---------------------------------------------------------------- |
|
1009 |
{ |
|
17441
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1010 |
clear(c); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1011 |
try { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1012 |
c.removeAll(null); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1013 |
fail("Expected NullPointerException"); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1014 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1015 |
catch (NullPointerException e) { pass(); } |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1016 |
catch (Throwable t) { unexpected(t); } |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1017 |
|
2 | 1018 |
oneElement(c); |
1019 |
try { |
|
1020 |
c.removeAll(null); |
|
1021 |
fail("Expected NullPointerException"); |
|
1022 |
} |
|
1023 |
catch (NullPointerException e) { pass(); } |
|
1024 |
catch (Throwable t) { unexpected(t); } |
|
1025 |
||
17441
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1026 |
clear(c); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1027 |
try { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1028 |
c.retainAll(null); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1029 |
fail("Expected NullPointerException"); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1030 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1031 |
catch (NullPointerException e) { pass(); } |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1032 |
catch (Throwable t) { unexpected(t); } |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1033 |
|
2 | 1034 |
oneElement(c); |
1035 |
try { |
|
1036 |
c.retainAll(null); |
|
1037 |
fail("Expected NullPointerException"); |
|
1038 |
} |
|
1039 |
catch (NullPointerException e) { pass(); } |
|
1040 |
catch (Throwable t) { unexpected(t); } |
|
1041 |
||
1042 |
oneElement(c); |
|
1043 |
try { |
|
1044 |
c.addAll(null); |
|
1045 |
fail("Expected NullPointerException"); |
|
1046 |
} |
|
1047 |
catch (NullPointerException e) { pass(); } |
|
1048 |
catch (Throwable t) { unexpected(t); } |
|
1049 |
||
1050 |
oneElement(c); |
|
1051 |
try { |
|
1052 |
c.containsAll(null); |
|
1053 |
fail("Expected NullPointerException"); |
|
1054 |
} |
|
1055 |
catch (NullPointerException e) { pass(); } |
|
1056 |
catch (Throwable t) { unexpected(t); } |
|
1057 |
} |
|
1058 |
} |
|
1059 |
||
1060 |
//---------------------------------------------------------------- |
|
1061 |
// Map |
|
1062 |
//---------------------------------------------------------------- |
|
1063 |
private static void checkFunctionalInvariants(Map<Integer,Integer> m) { |
|
1064 |
check(m.keySet().size() == m.entrySet().size()); |
|
1065 |
check(m.keySet().size() == m.size()); |
|
1066 |
checkFunctionalInvariants(m.keySet()); |
|
1067 |
checkFunctionalInvariants(m.values()); |
|
1068 |
check(m.size() != 0 ^ m.isEmpty()); |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1069 |
check(! m.containsKey(ABSENT_VALUE)); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1070 |
|
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1071 |
if (m instanceof Serializable) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1072 |
//System.out.printf("Serializing %s%n", m.getClass().getName()); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1073 |
try { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1074 |
Object clone = serialClone(m); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1075 |
equal(m instanceof Serializable, |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1076 |
clone instanceof Serializable); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1077 |
equal(m, clone); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1078 |
} catch (Error xxx) { |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1079 |
if (! (xxx.getCause() instanceof NotSerializableException)) |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1080 |
throw xxx; |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1081 |
} |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1082 |
} |
2 | 1083 |
} |
1084 |
||
1085 |
private static void testMap(Map<Integer,Integer> m) { |
|
1086 |
System.out.println("\n==> " + m.getClass().getName()); |
|
1087 |
||
1088 |
if (m instanceof ConcurrentMap) |
|
1089 |
testConcurrentMap((ConcurrentMap<Integer,Integer>) m); |
|
1090 |
||
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1091 |
if (m instanceof NavigableMap) { |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1092 |
System.out.println("NavigableMap tests..."); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1093 |
|
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1094 |
NavigableMap<Integer,Integer> nm = |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1095 |
(NavigableMap<Integer,Integer>) m; |
2428
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1096 |
testNavigableMapRemovers(nm); |
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1097 |
testNavigableMap(nm); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1098 |
testNavigableMap(nm.headMap(6, false)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1099 |
testNavigableMap(nm.headMap(5, true)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1100 |
testNavigableMap(nm.tailMap(0, false)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1101 |
testNavigableMap(nm.tailMap(1, true)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1102 |
testNavigableMap(nm.subMap(1, true, 6, false)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1103 |
testNavigableMap(nm.subMap(0, false, 5, true)); |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1104 |
} |
2 | 1105 |
|
1106 |
checkFunctionalInvariants(m); |
|
1107 |
||
1108 |
if (supportsClear(m)) { |
|
1109 |
try { clear(m); } |
|
1110 |
catch (Throwable t) { unexpected(t); } |
|
1111 |
} |
|
1112 |
||
1113 |
if (supportsPut(m)) { |
|
1114 |
try { |
|
1115 |
check(m.put(3333, 77777) == null); |
|
1116 |
check(m.put(9134, 74982) == null); |
|
1117 |
check(m.get(9134) == 74982); |
|
1118 |
check(m.put(9134, 1382) == 74982); |
|
1119 |
check(m.get(9134) == 1382); |
|
1120 |
check(m.size() == 2); |
|
1121 |
checkFunctionalInvariants(m); |
|
1122 |
checkNPEConsistency(m); |
|
1123 |
} |
|
1124 |
catch (Throwable t) { unexpected(t); } |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
1128 |
private static boolean supportsPut(Map<Integer,Integer> m) { |
|
1129 |
// We're asking for .equals(...) semantics |
|
1130 |
if (m instanceof IdentityHashMap) return false; |
|
1131 |
||
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1132 |
try { check(m.put(ABSENT_VALUE,12735) == null); } |
2 | 1133 |
catch (UnsupportedOperationException t) { return false; } |
1134 |
catch (Throwable t) { unexpected(t); } |
|
1135 |
||
1136 |
try { |
|
34527
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1137 |
check(m.containsKey(ABSENT_VALUE)); |
e3caf3a43d09
8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
32991
diff
changeset
|
1138 |
check(m.remove(ABSENT_VALUE) != null); |
2 | 1139 |
} catch (Throwable t) { unexpected(t); } |
1140 |
return true; |
|
1141 |
} |
|
1142 |
||
1143 |
private static boolean supportsClear(Map<?,?> m) { |
|
1144 |
try { m.clear(); } |
|
1145 |
catch (UnsupportedOperationException t) { return false; } |
|
1146 |
catch (Throwable t) { unexpected(t); } |
|
1147 |
return true; |
|
1148 |
} |
|
1149 |
||
1150 |
//---------------------------------------------------------------- |
|
1151 |
// ConcurrentMap |
|
1152 |
//---------------------------------------------------------------- |
|
1153 |
private static void testConcurrentMap(ConcurrentMap<Integer,Integer> m) { |
|
1154 |
System.out.println("ConcurrentMap tests..."); |
|
1155 |
||
1156 |
try { |
|
1157 |
clear(m); |
|
1158 |
||
1159 |
check(m.putIfAbsent(18357,7346) == null); |
|
1160 |
check(m.containsKey(18357)); |
|
1161 |
check(m.putIfAbsent(18357,8263) == 7346); |
|
1162 |
try { m.putIfAbsent(18357,null); fail("NPE"); } |
|
1163 |
catch (NullPointerException t) { } |
|
1164 |
check(m.containsKey(18357)); |
|
1165 |
||
1166 |
check(! m.replace(18357,8888,7777)); |
|
1167 |
check(m.containsKey(18357)); |
|
1168 |
try { m.replace(18357,null,7777); fail("NPE"); } |
|
1169 |
catch (NullPointerException t) { } |
|
1170 |
check(m.containsKey(18357)); |
|
1171 |
check(m.get(18357) == 7346); |
|
1172 |
check(m.replace(18357,7346,5555)); |
|
1173 |
check(m.replace(18357,5555,7346)); |
|
1174 |
check(m.get(18357) == 7346); |
|
1175 |
||
1176 |
check(m.replace(92347,7834) == null); |
|
1177 |
try { m.replace(18357,null); fail("NPE"); } |
|
1178 |
catch (NullPointerException t) { } |
|
1179 |
check(m.replace(18357,7346) == 7346); |
|
1180 |
check(m.replace(18357,5555) == 7346); |
|
1181 |
check(m.get(18357) == 5555); |
|
1182 |
check(m.replace(18357,7346) == 5555); |
|
1183 |
check(m.get(18357) == 7346); |
|
1184 |
||
1185 |
check(! m.remove(18357,9999)); |
|
1186 |
check(m.get(18357) == 7346); |
|
1187 |
check(m.containsKey(18357)); |
|
1188 |
check(! m.remove(18357,null)); // 6272521 |
|
1189 |
check(m.get(18357) == 7346); |
|
1190 |
check(m.remove(18357,7346)); |
|
1191 |
check(m.get(18357) == null); |
|
1192 |
check(! m.containsKey(18357)); |
|
1193 |
check(m.isEmpty()); |
|
1194 |
||
1195 |
m.putIfAbsent(1,2); |
|
1196 |
check(m.size() == 1); |
|
1197 |
check(! m.remove(1,null)); |
|
1198 |
check(! m.remove(1,null)); |
|
1199 |
check(! m.remove(1,1)); |
|
1200 |
check(m.remove(1,2)); |
|
1201 |
check(m.isEmpty()); |
|
1202 |
||
1203 |
testEmptyMap(m); |
|
1204 |
} |
|
1205 |
catch (Throwable t) { unexpected(t); } |
|
1206 |
} |
|
1207 |
||
1208 |
private static void throwsConsistently(Class<? extends Throwable> k, |
|
1209 |
Iterable<Fun> fs) { |
|
1210 |
List<Class<? extends Throwable>> threw |
|
1211 |
= new ArrayList<Class<? extends Throwable>>(); |
|
1212 |
for (Fun f : fs) |
|
1213 |
try { f.f(); threw.add(null); } |
|
1214 |
catch (Throwable t) { |
|
1215 |
check(k.isAssignableFrom(t.getClass())); |
|
1216 |
threw.add(t.getClass()); |
|
1217 |
} |
|
1218 |
if (new HashSet<Object>(threw).size() != 1) |
|
1219 |
fail(threw.toString()); |
|
1220 |
} |
|
1221 |
||
1222 |
private static <T> void checkNPEConsistency(final Map<T,Integer> m) { |
|
1223 |
m.clear(); |
|
1224 |
final ConcurrentMap<T,Integer> cm = (m instanceof ConcurrentMap) |
|
1225 |
? (ConcurrentMap<T,Integer>) m |
|
1226 |
: null; |
|
1227 |
List<Fun> fs = new ArrayList<Fun>(); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1228 |
fs.add(() -> check(! m.containsKey(null))); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1229 |
fs.add(() -> equal(m.remove(null), null)); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1230 |
fs.add(() -> equal(m.get(null), null)); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1231 |
if (cm != null) |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1232 |
fs.add(() -> check(! cm.remove(null,null))); |
2 | 1233 |
throwsConsistently(NullPointerException.class, fs); |
1234 |
||
1235 |
fs.clear(); |
|
1236 |
final Map<T,Integer> sm = singletonMap(null,1); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1237 |
fs.add(() -> { equal(m.put(null,1), null); m.clear();}); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1238 |
fs.add(() -> { m.putAll(sm); m.clear();}); |
2 | 1239 |
if (cm != null) { |
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1240 |
fs.add(() -> check(! cm.remove(null,null))); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1241 |
fs.add(() -> equal(cm.putIfAbsent(null,1), 1)); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1242 |
fs.add(() -> equal(cm.replace(null,1), null)); |
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1243 |
fs.add(() -> equal(cm.replace(null,1, 1), 1)); |
2 | 1244 |
} |
1245 |
throwsConsistently(NullPointerException.class, fs); |
|
1246 |
} |
|
1247 |
||
1248 |
//---------------------------------------------------------------- |
|
1249 |
// NavigableMap |
|
1250 |
//---------------------------------------------------------------- |
|
1251 |
private static void |
|
1252 |
checkNavigableMapKeys(NavigableMap<Integer,Integer> m, |
|
1253 |
Integer i, |
|
1254 |
Integer lower, |
|
1255 |
Integer floor, |
|
1256 |
Integer ceiling, |
|
1257 |
Integer higher) { |
|
1258 |
equal(m.lowerKey(i), lower); |
|
1259 |
equal(m.floorKey(i), floor); |
|
1260 |
equal(m.ceilingKey(i), ceiling); |
|
1261 |
equal(m.higherKey(i), higher); |
|
1262 |
} |
|
1263 |
||
1264 |
private static void |
|
1265 |
checkNavigableSetKeys(NavigableSet<Integer> m, |
|
1266 |
Integer i, |
|
1267 |
Integer lower, |
|
1268 |
Integer floor, |
|
1269 |
Integer ceiling, |
|
1270 |
Integer higher) { |
|
1271 |
equal(m.lower(i), lower); |
|
1272 |
equal(m.floor(i), floor); |
|
1273 |
equal(m.ceiling(i), ceiling); |
|
1274 |
equal(m.higher(i), higher); |
|
1275 |
} |
|
1276 |
||
1277 |
static final Random rnd = new Random(); |
|
1278 |
static void equalNext(final Iterator<?> it, Object expected) { |
|
1279 |
if (rnd.nextBoolean()) |
|
1280 |
check(it.hasNext()); |
|
1281 |
equal(it.next(), expected); |
|
1282 |
} |
|
1283 |
||
2428
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1284 |
static void equalMaps(Map m1, Map m2) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1285 |
equal(m1, m2); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1286 |
equal(m2, m1); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1287 |
equal(m1.size(), m2.size()); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1288 |
equal(m1.isEmpty(), m2.isEmpty()); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1289 |
equal(m1.toString(), m2.toString()); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1290 |
check(Arrays.equals(m1.entrySet().toArray(), m2.entrySet().toArray())); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1291 |
} |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1292 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1293 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1294 |
static void testNavigableMapRemovers(NavigableMap m) |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1295 |
{ |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1296 |
final Map emptyMap = new HashMap(); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1297 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1298 |
final Map singletonMap = new HashMap(); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1299 |
singletonMap.put(1, 2); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1300 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1301 |
abstract class NavigableMapView { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1302 |
abstract NavigableMap view(NavigableMap m); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1303 |
} |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1304 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1305 |
NavigableMapView[] views = { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1306 |
new NavigableMapView() { NavigableMap view(NavigableMap m) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1307 |
return m; }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1308 |
new NavigableMapView() { NavigableMap view(NavigableMap m) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1309 |
return m.headMap(99, true); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1310 |
new NavigableMapView() { NavigableMap view(NavigableMap m) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1311 |
return m.tailMap(-99, false); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1312 |
new NavigableMapView() { NavigableMap view(NavigableMap m) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1313 |
return m.subMap(-99, true, 99, false); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1314 |
}; |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1315 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1316 |
abstract class Remover { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1317 |
abstract void remove(NavigableMap m, Object k, Object v); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1318 |
} |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1319 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1320 |
Remover[] removers = { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1321 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1322 |
equal(m.remove(k), v); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1323 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1324 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1325 |
equal(m.descendingMap().remove(k), v); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1326 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1327 |
equal(m.descendingMap().headMap(-86, false).remove(k), v); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1328 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1329 |
equal(m.descendingMap().tailMap(86, true).remove(k), v); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1330 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1331 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1332 |
equal(m.headMap(86, true).remove(k), v); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1333 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1334 |
equal(m.tailMap(-86, true).remove(k), v); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1335 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1336 |
equal(m.subMap(-86, false, 86, true).remove(k), v); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1337 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1338 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1339 |
check(m.keySet().remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1340 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1341 |
check(m.navigableKeySet().remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1342 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1343 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1344 |
check(m.navigableKeySet().headSet(86, true).remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1345 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1346 |
check(m.navigableKeySet().tailSet(-86, false).remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1347 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1348 |
check(m.navigableKeySet().subSet(-86, true, 86, false) |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1349 |
.remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1350 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1351 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1352 |
check(m.descendingKeySet().headSet(-86, false).remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1353 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1354 |
check(m.descendingKeySet().tailSet(86, true).remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1355 |
new Remover() { void remove(NavigableMap m, Object k, Object v) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1356 |
check(m.descendingKeySet().subSet(86, true, -86, false) |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1357 |
.remove(k)); }}, |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1358 |
}; |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1359 |
|
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1360 |
for (NavigableMapView view : views) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1361 |
for (Remover remover : removers) { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1362 |
try { |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1363 |
m.clear(); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1364 |
equalMaps(m, emptyMap); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1365 |
equal(m.put(1, 2), null); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1366 |
equalMaps(m, singletonMap); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1367 |
NavigableMap v = view.view(m); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1368 |
remover.remove(v, 1, 2); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1369 |
equalMaps(m, emptyMap); |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1370 |
} catch (Throwable t) { unexpected(t); } |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1371 |
} |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1372 |
} |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1373 |
} |
e63d91602813
6800572: Removing elements from views of NavigableMap implementations does not always work correctly.
dl
parents:
494
diff
changeset
|
1374 |
|
2 | 1375 |
private static void testNavigableMap(NavigableMap<Integer,Integer> m) |
1376 |
{ |
|
1377 |
clear(m); |
|
1378 |
checkNavigableMapKeys(m, 1, null, null, null, null); |
|
1379 |
||
1380 |
equal(m.put(1, 2), null); |
|
1381 |
equal(m.put(3, 4), null); |
|
1382 |
equal(m.put(5, 9), null); |
|
1383 |
||
1384 |
equal(m.put(1, 2), 2); |
|
1385 |
equal(m.put(3, 4), 4); |
|
1386 |
equal(m.put(5, 6), 9); |
|
1387 |
||
1388 |
checkNavigableMapKeys(m, 0, null, null, 1, 1); |
|
1389 |
checkNavigableMapKeys(m, 1, null, 1, 1, 3); |
|
1390 |
checkNavigableMapKeys(m, 2, 1, 1, 3, 3); |
|
1391 |
checkNavigableMapKeys(m, 3, 1, 3, 3, 5); |
|
1392 |
checkNavigableMapKeys(m, 5, 3, 5, 5, null); |
|
1393 |
checkNavigableMapKeys(m, 6, 5, 5, null, null); |
|
1394 |
||
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1395 |
for (final Iterator<Integer> it : |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1396 |
(Iterator<Integer>[]) |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1397 |
new Iterator<?>[] { |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1398 |
m.descendingKeySet().iterator(), |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1399 |
m.navigableKeySet().descendingIterator()}) { |
2 | 1400 |
equalNext(it, 5); |
1401 |
equalNext(it, 3); |
|
1402 |
equalNext(it, 1); |
|
1403 |
check(! it.hasNext()); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1404 |
THROWS(NoSuchElementException.class, () -> it.next()); |
2 | 1405 |
} |
1406 |
||
1407 |
{ |
|
1408 |
final Iterator<Map.Entry<Integer,Integer>> it |
|
1409 |
= m.descendingMap().entrySet().iterator(); |
|
1410 |
check(it.hasNext()); equal(it.next().getKey(), 5); |
|
1411 |
check(it.hasNext()); equal(it.next().getKey(), 3); |
|
1412 |
check(it.hasNext()); equal(it.next().getKey(), 1); |
|
1413 |
check(! it.hasNext()); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1414 |
THROWS(NoSuchElementException.class, () -> it.next()); |
2 | 1415 |
} |
20757
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1416 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1417 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1418 |
checkDescItrRmFirst(m.keySet(), m.navigableKeySet().descendingIterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1419 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1420 |
checkDescItrRmMid(m.keySet(), m.navigableKeySet().descendingIterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1421 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1422 |
checkDescItrRmLast(m.keySet(), m.navigableKeySet().descendingIterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1423 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1424 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1425 |
checkDescItrRmFirst(m.keySet(), m.descendingMap().keySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1426 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1427 |
checkDescItrRmMid(m.keySet(), m.descendingMap().keySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1428 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1429 |
checkDescItrRmLast(m.keySet(), m.descendingMap().keySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1430 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1431 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1432 |
checkDescItrRmFirst(m.keySet(), m.descendingKeySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1433 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1434 |
checkDescItrRmMid(m.keySet(), m.descendingKeySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1435 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1436 |
checkDescItrRmLast(m.keySet(), m.descendingKeySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1437 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1438 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1439 |
checkDescItrRmFirst(m.values(), m.descendingMap().values().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1440 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1441 |
checkDescItrRmMid(m.values(), m.descendingMap().values().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1442 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1443 |
checkDescItrRmLast(m.values(), m.descendingMap().values().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1444 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1445 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1446 |
checkDescItrRmFirst((Collection)m.entrySet(), |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1447 |
m.descendingMap().entrySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1448 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1449 |
checkDescItrRmMid((Collection)m.entrySet(), |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1450 |
m.descendingMap().entrySet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1451 |
prepMapForDescItrTests(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1452 |
checkDescItrRmLast((Collection)m.entrySet(), |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1453 |
m.descendingMap().entrySet().iterator()); |
2 | 1454 |
} |
1455 |
||
1456 |
private static void testNavigableSet(NavigableSet<Integer> s) { |
|
1457 |
clear(s); |
|
1458 |
checkNavigableSetKeys(s, 1, null, null, null, null); |
|
1459 |
||
1460 |
check(s.add(1)); |
|
1461 |
check(s.add(3)); |
|
1462 |
check(s.add(5)); |
|
1463 |
||
1464 |
check(! s.add(1)); |
|
1465 |
check(! s.add(3)); |
|
1466 |
check(! s.add(5)); |
|
1467 |
||
1468 |
checkNavigableSetKeys(s, 0, null, null, 1, 1); |
|
1469 |
checkNavigableSetKeys(s, 1, null, 1, 1, 3); |
|
1470 |
checkNavigableSetKeys(s, 2, 1, 1, 3, 3); |
|
1471 |
checkNavigableSetKeys(s, 3, 1, 3, 3, 5); |
|
1472 |
checkNavigableSetKeys(s, 5, 3, 5, 5, null); |
|
1473 |
checkNavigableSetKeys(s, 6, 5, 5, null, null); |
|
1474 |
||
493
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1475 |
for (final Iterator<Integer> it : |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1476 |
(Iterator<Integer>[]) |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1477 |
new Iterator<?>[] { |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1478 |
s.descendingIterator(), |
b8102e80be10
6691185: (coll) TreeMap.navigableKeySet's descendingIterator method starts at first instead of last entry
martin
parents:
2
diff
changeset
|
1479 |
s.descendingSet().iterator()}) { |
2 | 1480 |
equalNext(it, 5); |
1481 |
equalNext(it, 3); |
|
1482 |
equalNext(it, 1); |
|
1483 |
check(! it.hasNext()); |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1484 |
THROWS(NoSuchElementException.class, () -> it.next()); |
2 | 1485 |
} |
20757
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1486 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1487 |
prepSetForDescItrTests(s); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1488 |
checkDescItrRmFirst(s, s.descendingIterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1489 |
prepSetForDescItrTests(s); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1490 |
checkDescItrRmMid(s, s.descendingIterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1491 |
prepSetForDescItrTests(s); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1492 |
checkDescItrRmLast(s, s.descendingIterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1493 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1494 |
prepSetForDescItrTests(s); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1495 |
checkDescItrRmFirst(s, s.descendingSet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1496 |
prepSetForDescItrTests(s); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1497 |
checkDescItrRmMid(s, s.descendingSet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1498 |
prepSetForDescItrTests(s); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1499 |
checkDescItrRmLast(s, s.descendingSet().iterator()); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1500 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1501 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1502 |
private static void prepSetForDescItrTests(Set s) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1503 |
clear(s); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1504 |
check(s.add(1)); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1505 |
check(s.add(3)); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1506 |
check(s.add(5)); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1507 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1508 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1509 |
private static void prepMapForDescItrTests(Map m) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1510 |
clear(m); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1511 |
equal(m.put(1, 2), null); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1512 |
equal(m.put(3, 4), null); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1513 |
equal(m.put(5, 9), null); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1514 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1515 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1516 |
//-------------------------------------------------------------------- |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1517 |
// Check behavior of descending iterator when first element is removed |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1518 |
//-------------------------------------------------------------------- |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1519 |
private static <T> void checkDescItrRmFirst(Collection<T> ascColl, |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1520 |
Iterator<T> descItr) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1521 |
T[] expected = (T[]) ascColl.toArray(); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1522 |
int idx = expected.length -1; |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1523 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1524 |
equalNext(descItr, expected[idx--]); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1525 |
descItr.remove(); |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
31540
diff
changeset
|
1526 |
while (idx >= 0 && descItr.hasNext()) { |
20757
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1527 |
equalNext(descItr, expected[idx--]); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1528 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1529 |
equal(descItr.hasNext(), false); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1530 |
equal(idx, -1); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1531 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1532 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1533 |
//----------------------------------------------------------------------- |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1534 |
// Check behavior of descending iterator when a middle element is removed |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1535 |
//----------------------------------------------------------------------- |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1536 |
private static <T> void checkDescItrRmMid(Collection<T> ascColl, |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1537 |
Iterator<T> descItr) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1538 |
T[] expected = (T[]) ascColl.toArray(); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1539 |
int idx = expected.length -1; |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1540 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1541 |
while (idx >= expected.length / 2) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1542 |
equalNext(descItr, expected[idx--]); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1543 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1544 |
descItr.remove(); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1545 |
while (idx >= 0 && descItr.hasNext()) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1546 |
equalNext(descItr, expected[idx--]); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1547 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1548 |
equal(descItr.hasNext(), false); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1549 |
equal(idx, -1); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1550 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1551 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1552 |
//----------------------------------------------------------------------- |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1553 |
// Check behavior of descending iterator when the last element is removed |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1554 |
//----------------------------------------------------------------------- |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1555 |
private static <T> void checkDescItrRmLast(Collection<T> ascColl, |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1556 |
Iterator<T> descItr) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1557 |
T[] expected = (T[]) ascColl.toArray(); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1558 |
int idx = expected.length -1; |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1559 |
|
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1560 |
while (idx >= 0 && descItr.hasNext()) { |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1561 |
equalNext(descItr, expected[idx--]); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1562 |
} |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1563 |
equal(idx, -1); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1564 |
equal(descItr.hasNext(), false); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1565 |
descItr.remove(); |
1e9f01f43f5c
8024709: TreeMap.DescendingKeyIterator 'remove' confuses iterator position
bchristi
parents:
20476
diff
changeset
|
1566 |
equal(ascColl.contains(expected[0]), false); |
2 | 1567 |
} |
1568 |
||
1569 |
//--------------------- Infrastructure --------------------------- |
|
1570 |
static volatile int passed = 0, failed = 0; |
|
1571 |
static void pass() { passed++; } |
|
1572 |
static void fail() { failed++; Thread.dumpStack(); } |
|
1573 |
static void fail(String msg) { System.out.println(msg); fail(); } |
|
1574 |
static void unexpected(Throwable t) { failed++; t.printStackTrace(); } |
|
1575 |
static void check(boolean cond) { if (cond) pass(); else fail(); } |
|
1576 |
static void equal(Object x, Object y) { |
|
1577 |
if (x == null ? y == null : x.equals(y)) pass(); |
|
1578 |
else {System.out.println(x + " not equal to " + y); fail();}} |
|
1579 |
static void equal2(Object x, Object y) {equal(x, y); equal(y, x);} |
|
1580 |
public static void main(String[] args) throws Throwable { |
|
1581 |
try { realMain(args); } catch (Throwable t) { unexpected(t); } |
|
1582 |
||
1583 |
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
|
1584 |
if (failed > 0) throw new Exception("Some tests failed"); |
|
1585 |
} |
|
24692
268fbc344d53
8037866: Replace the Fun class in tests with lambdas
igerasim
parents:
23580
diff
changeset
|
1586 |
interface Fun {void f() throws Throwable;} |
2 | 1587 |
private static void THROWS(Class<? extends Throwable> k, Fun... fs) { |
1588 |
for (Fun f : fs) |
|
1589 |
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } |
|
1590 |
catch (Throwable t) { |
|
1591 |
if (k.isAssignableFrom(t.getClass())) pass(); |
|
1592 |
else unexpected(t);}} |
|
1593 |
static byte[] serializedForm(Object obj) { |
|
1594 |
try { |
|
1595 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
1596 |
new ObjectOutputStream(baos).writeObject(obj); |
|
1597 |
return baos.toByteArray(); |
|
1598 |
} catch (IOException e) { throw new Error(e); }} |
|
1599 |
static Object readObject(byte[] bytes) |
|
1600 |
throws IOException, ClassNotFoundException { |
|
1601 |
InputStream is = new ByteArrayInputStream(bytes); |
|
1602 |
return new ObjectInputStream(is).readObject();} |
|
1603 |
@SuppressWarnings("unchecked") |
|
1604 |
static <T> T serialClone(T obj) { |
|
1605 |
try { return (T) readObject(serializedForm(obj)); } |
|
1606 |
catch (Exception e) { throw new Error(e); }} |
|
17441
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1607 |
private static class NewAbstractCollection<E> extends AbstractCollection<E> { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1608 |
ArrayList<E> list = new ArrayList<>(); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1609 |
public boolean remove(Object obj) { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1610 |
return list.remove(obj); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1611 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1612 |
public boolean add(E e) { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1613 |
return list.add(e); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1614 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1615 |
public Iterator<E> iterator() { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1616 |
return list.iterator(); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1617 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1618 |
public int size() { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1619 |
return list.size(); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1620 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1621 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1622 |
private static class NewAbstractSet<E> extends AbstractSet<E> { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1623 |
HashSet<E> set = new HashSet<>(); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1624 |
public boolean remove(Object obj) { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1625 |
return set.remove(obj); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1626 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1627 |
public boolean add(E e) { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1628 |
return set.add(e); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1629 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1630 |
public Iterator<E> iterator() { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1631 |
return set.iterator(); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1632 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1633 |
public int size() { |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1634 |
return set.size(); |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1635 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1636 |
} |
5ae43433d158
4802647: Throw required NPEs from removeAll()/retainAll()
mduigou
parents:
9035
diff
changeset
|
1637 |
|
2 | 1638 |
} |