0N/A/*
2362N/A * Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4152868
0N/A * @summary test Case Insensitive Comparator in String
0N/A */
0N/A
0N/Aimport java.util.*;
0N/A
0N/Apublic class ICCBasher {
0N/A
0N/A static final int TEST_SIZE = 20;
0N/A static final int STRING_SIZE = 5;
0N/A static final int CHAR_VALUE_LIMIT = 128;
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A LinkedList L1 = new LinkedList();
0N/A LinkedList L2 = new LinkedList();
0N/A LinkedList L3 = new LinkedList();
0N/A LinkedList L4 = new LinkedList();
0N/A
0N/A // First generate L1 and L2 with random lower case chars
0N/A //System.out.println("Generate L1 and L2");
0N/A Random generator = new Random();
0N/A int achar=0;
0N/A StringBuffer entryBuffer = new StringBuffer(10);
0N/A String snippet = null;
0N/A for (int x=0; x<TEST_SIZE * 2; x++) {
0N/A for(int y=0; y<STRING_SIZE; y++) {
0N/A achar = generator.nextInt(CHAR_VALUE_LIMIT);
0N/A char test = (char)(achar);
0N/A entryBuffer.append(test);
0N/A }
0N/A snippet = entryBuffer.toString();
0N/A snippet.toLowerCase();
0N/A if (x < TEST_SIZE)
0N/A L1.add(snippet);
0N/A else
0N/A L2.add(snippet);
0N/A }
0N/A
0N/A // Concatenate L1 and L2 to form L3
0N/A //System.out.println("Generate L3");
0N/A for (int x=0; x<TEST_SIZE; x++) {
0N/A String entry = (String)L1.get(x) + (String)L2.get(x);
0N/A L3.add(entry);
0N/A }
0N/A
0N/A // Randomly toUpper L1 and L2
0N/A //System.out.println("Modify L1 and L2");
0N/A for (int x=0; x<TEST_SIZE; x++) {
0N/A achar = generator.nextInt();
0N/A if (achar > 0) {
0N/A String mod = (String)L1.get(x);
0N/A mod = mod.toUpperCase();
0N/A L1.set(x, mod);
0N/A }
0N/A achar = generator.nextInt();
0N/A if (achar > 0) {
0N/A String mod = (String)L2.get(x);
0N/A mod = mod.toUpperCase();
0N/A L2.set(x, mod);
0N/A }
0N/A }
0N/A
0N/A // Concatenate L1 and L2 to form L4
0N/A //System.out.println("Generate L4");
0N/A for (int x=0; x<TEST_SIZE; x++) {
0N/A String entry = (String)L1.get(x) + (String)L2.get(x);
0N/A L4.add(entry);
0N/A }
0N/A
0N/A // Sort L3 and L4 using case insensitive comparator
0N/A //System.out.println("Sort L3 and L4");
0N/A Collections.sort(L3, String.CASE_INSENSITIVE_ORDER);
0N/A Collections.sort(L4, String.CASE_INSENSITIVE_ORDER);
0N/A
0N/A // Check to see that order of L3 and L4 are identical
0N/A // ignoring case considerations
0N/A //System.out.println("Check order of L3 and L4");
0N/A for (int x=0; x<TEST_SIZE; x++) {
0N/A String one = (String)L3.get(x);
0N/A String two = (String)L4.get(x);
0N/A if (!one.equalsIgnoreCase(two))
0N/A throw new RuntimeException("Case Insensitive Sort Failure.");
0N/A }
0N/A
0N/A }
0N/A}