Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/ArrayList/AddAll.java
38811 views
/*1* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 471520626* @summary Ensure that addAll method can cope with underestimate by size().27* @author Josh Bloch28*/2930import java.util.*;3132public class AddAll {33public static void main(String[] args) {34for (int j = 0; j < 1; j++) {35Map m = new WeakHashMap(100000);36for (int i = 0; i < 100000; i++)37m.put(new Object(), Boolean.TRUE);38new ArrayList().addAll(m.keySet());39}4041for (int j = 0; j < 1; j++) {42Map m = new WeakHashMap(100000);43for (int i = 0; i < 100000; i++)44m.put(new Object(), Boolean.TRUE);45new LinkedList().addAll(m.keySet());46}4748for (int j = 0; j < 1; j++) {49Map m = new WeakHashMap(100000);50for (int i = 0; i < 100000; i++)51m.put(new Object(), Boolean.TRUE);52new Vector().addAll(m.keySet());53}5455for (int j = 0; j < 1; j++) {56Map m = new WeakHashMap(100000);57for (int i = 0; i < 100000; i++)58m.put(new Object(), Boolean.TRUE);59List list = new ArrayList();60list.add("inka"); list.add("dinka"); list.add("doo");61list.addAll(1, m.keySet());62}6364for (int j = 0; j < 1; j++) {65Map m = new WeakHashMap(100000);66for (int i = 0; i < 100000; i++)67m.put(new Object(), Boolean.TRUE);68List list = new LinkedList();69list.add("inka"); list.add("dinka"); list.add("doo");70list.addAll(1, m.keySet());71}7273for (int j = 0; j < 1; j++) {74Map m = new WeakHashMap(100000);75for (int i = 0; i < 100000; i++)76m.put(new Object(), Boolean.TRUE);77List list = new ArrayList();78list.add("inka"); list.add("dinka"); list.add("doo");79list.addAll(1, m.keySet());80}81}82}838485