1 |
/* |
2 |
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. |
8 |
* |
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
13 |
* accompanied this code). |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License version |
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
* |
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
21 |
* questions. |
22 |
*/ |
23 |
|
24 |
/* |
25 |
* @test |
26 |
* @bug 4715206 |
27 |
* @summary Ensure that addAll method can cope with underestimate by size(). |
28 |
* @author Josh Bloch |
29 |
*/ |
30 |
|
31 |
import java.util.ArrayList; |
32 |
import java.util.LinkedList; |
33 |
import java.util.List; |
34 |
import java.util.Map; |
35 |
import java.util.Vector; |
36 |
import java.util.WeakHashMap; |
37 |
|
38 |
public class AddAll { |
39 |
public static void main(String[] args) { |
40 |
for (int j = 0; j < 1; j++) { |
41 |
Map m = new WeakHashMap(100000); |
42 |
for (int i = 0; i < 100000; i++) |
43 |
m.put(new Object(), Boolean.TRUE); |
44 |
new ArrayList().addAll(m.keySet()); |
45 |
} |
46 |
|
47 |
for (int j = 0; j < 1; j++) { |
48 |
Map m = new WeakHashMap(100000); |
49 |
for (int i = 0; i < 100000; i++) |
50 |
m.put(new Object(), Boolean.TRUE); |
51 |
new LinkedList().addAll(m.keySet()); |
52 |
} |
53 |
|
54 |
for (int j = 0; j < 1; j++) { |
55 |
Map m = new WeakHashMap(100000); |
56 |
for (int i = 0; i < 100000; i++) |
57 |
m.put(new Object(), Boolean.TRUE); |
58 |
new Vector().addAll(m.keySet()); |
59 |
} |
60 |
|
61 |
for (int j = 0; j < 1; j++) { |
62 |
Map m = new WeakHashMap(100000); |
63 |
for (int i = 0; i < 100000; i++) |
64 |
m.put(new Object(), Boolean.TRUE); |
65 |
List list = new ArrayList(); |
66 |
list.add("inka"); list.add("dinka"); list.add("doo"); |
67 |
list.addAll(1, m.keySet()); |
68 |
} |
69 |
|
70 |
for (int j = 0; j < 1; j++) { |
71 |
Map m = new WeakHashMap(100000); |
72 |
for (int i = 0; i < 100000; i++) |
73 |
m.put(new Object(), Boolean.TRUE); |
74 |
List list = new LinkedList(); |
75 |
list.add("inka"); list.add("dinka"); list.add("doo"); |
76 |
list.addAll(1, m.keySet()); |
77 |
} |
78 |
|
79 |
for (int j = 0; j < 1; j++) { |
80 |
Map m = new WeakHashMap(100000); |
81 |
for (int i = 0; i < 100000; i++) |
82 |
m.put(new Object(), Boolean.TRUE); |
83 |
List list = new ArrayList(); |
84 |
list.add("inka"); list.add("dinka"); list.add("doo"); |
85 |
list.addAll(1, m.keySet()); |
86 |
} |
87 |
} |
88 |
} |