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 package test.java.util.ArrayList; 32 33 import java.util.ArrayList; 34 import java.util.LinkedList; 35 import java.util.List; 36 import java.util.Map; 37 import java.util.Vector; 38 import java.util.WeakHashMap; 39 40 public class AddAll { 41 main(String[] args)42 public static void main(String[] args) { 43 for (int j = 0; j < 1; j++) { 44 Map m = new WeakHashMap(100000); 45 for (int i = 0; i < 100000; i++) 46 m.put(new Object(), Boolean.TRUE); 47 new ArrayList().addAll(m.keySet()); 48 } 49 50 for (int j = 0; j < 1; j++) { 51 Map m = new WeakHashMap(100000); 52 for (int i = 0; i < 100000; i++) 53 m.put(new Object(), Boolean.TRUE); 54 new LinkedList().addAll(m.keySet()); 55 } 56 57 for (int j = 0; j < 1; j++) { 58 Map m = new WeakHashMap(100000); 59 for (int i = 0; i < 100000; i++) 60 m.put(new Object(), Boolean.TRUE); 61 new Vector().addAll(m.keySet()); 62 } 63 64 for (int j = 0; j < 1; j++) { 65 Map m = new WeakHashMap(100000); 66 for (int i = 0; i < 100000; i++) 67 m.put(new Object(), Boolean.TRUE); 68 List list = new ArrayList(); 69 list.add("inka"); list.add("dinka"); list.add("doo"); 70 list.addAll(1, m.keySet()); 71 } 72 73 for (int j = 0; j < 1; j++) { 74 Map m = new WeakHashMap(100000); 75 for (int i = 0; i < 100000; i++) 76 m.put(new Object(), Boolean.TRUE); 77 List list = new LinkedList(); 78 list.add("inka"); list.add("dinka"); list.add("doo"); 79 list.addAll(1, m.keySet()); 80 } 81 82 for (int j = 0; j < 1; j++) { 83 Map m = new WeakHashMap(100000); 84 for (int i = 0; i < 100000; i++) 85 m.put(new Object(), Boolean.TRUE); 86 List list = new ArrayList(); 87 list.add("inka"); list.add("dinka"); list.add("doo"); 88 list.addAll(1, m.keySet()); 89 } 90 } 91 } 92