Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Collections/NullComparator.java
38812 views
/*1* Copyright (c) 1999, 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 422427126* @summary A null Comparator is now specified to indicate natural ordering.27*/2829import java.util.*;3031public class NullComparator {32public static void main(String[] args) throws Exception {33List list = new ArrayList(100);34for (int i=0; i<100; i++)35list.add(new Integer(i));36List sorted = new ArrayList(list);37Collections.shuffle(list);3839Object a[] = list.toArray();40Arrays.sort(a, null);41if (!Arrays.asList(a).equals(sorted))42throw new Exception("Arrays.sort");43a = list.toArray();44Arrays.sort(a, 0, 100, null);45if (!Arrays.asList(a).equals(sorted))46throw new Exception("Arrays.sort(from, to)");47if (Arrays.binarySearch(a, new Integer(69)) != 69)48throw new Exception("Arrays.binarySearch");4950List tmp = new ArrayList(list);51Collections.sort(tmp, null);52if (!tmp.equals(sorted))53throw new Exception("Collections.sort");54if (Collections.binarySearch(tmp, new Integer(69)) != 69)55throw new Exception("Collections.binarySearch");56if (!Collections.min(list, null).equals(new Integer(0)))57throw new Exception("Collections.min");58if (!Collections.max(list, null).equals(new Integer(99)))59throw new Exception("Collections.max");60}61}626364