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