Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/PriorityQueue/RemoveContains.java
38812 views
/*1* Copyright (c) 2005, 2013, 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 6207984 626806826* @summary Test contains/remove equator compatibility27* @author Martin Buchholz28*/2930import java.util.*;31import java.util.concurrent.*;3233public class RemoveContains {34static volatile int passed = 0, failed = 0;3536static void fail(String msg) {37failed++;38new AssertionError(msg).printStackTrace();39}4041static void pass() {42passed++;43}4445static void unexpected(Throwable t) {46failed++;47t.printStackTrace();48}4950static void check(boolean condition, String msg) {51if (condition)52passed++;53else54fail(msg);55}5657static void check(boolean condition) {58check(condition, "Assertion failure");59}6061public static void main(String[] args) {62final Comparator<String> firstChar = new Comparator<String>() {63public int compare(String x, String y) {64return x.charAt(0) - y.charAt(0); }};6566test(new PriorityQueue<String>(firstChar));67test(new PriorityQueue<String>(10, firstChar));68test(new PriorityBlockingQueue<String>(10, firstChar));69test(new ArrayBlockingQueue<String>(10));70test(new LinkedBlockingQueue<String>(10));71test(new LinkedBlockingDeque<String>(10));72test(new LinkedTransferQueue<String>());73test(new ArrayDeque<String>(10));7475System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);76if (failed > 0) throw new Error("Some tests failed");77}7879private static void test(Queue<String> q) {80try {81List<String> words =82Arrays.asList("foo", "fee", "fi", "fo", "fum",83"Englishman");84q.addAll(words);85for (String word : words)86check(q.contains(word));87check(! q.contains("flurble"));8889check(q.remove("fi"));90for (String word : words)91check(q.contains(word) ^ word.equals("fi"));9293check(! q.remove("fi"));94check(! q.remove("flurble"));9596} catch (Throwable t) { unexpected(t); }97}98}99100101