Path: blob/master/test/jdk/java/util/Collections/NullComparator.java
41149 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.ArrayList;30import java.util.Arrays;31import java.util.Collections;32import java.util.List;3334public class NullComparator {35public static void main(String[] args) throws Exception {36List list = new ArrayList(100);37for (int i=0; i<100; i++)38list.add(new Integer(i));39List sorted = new ArrayList(list);40Collections.shuffle(list);4142Object[] a = list.toArray();43Arrays.sort(a, null);44if (!Arrays.asList(a).equals(sorted))45throw new Exception("Arrays.sort");46a = list.toArray();47Arrays.sort(a, 0, 100, null);48if (!Arrays.asList(a).equals(sorted))49throw new Exception("Arrays.sort(from, to)");50if (Arrays.binarySearch(a, new Integer(69)) != 69)51throw new Exception("Arrays.binarySearch");5253List tmp = new ArrayList(list);54Collections.sort(tmp, null);55if (!tmp.equals(sorted))56throw new Exception("Collections.sort");57if (Collections.binarySearch(tmp, new Integer(69)) != 69)58throw new Exception("Collections.binarySearch");59if (!Collections.min(list, null).equals(new Integer(0)))60throw new Exception("Collections.min");61if (!Collections.max(list, null).equals(new Integer(99)))62throw new Exception("Collections.max");63}64}656667